python - 将列表中的所有术语转换为标题大小写
问题描述
我有一个清单:
['CHEVRON' 'GUNVOR' 'P66' 'SHELL']
我需要将它们转换为标题格式。
我目前正在遍历它们,但必须有一种更简单的方法。
预期输出:
['Chevron', 'Gunvor', 'P66', 'Shell']
解决方案
In [35]: L = ['CHEVRON', 'GUNVOR', 'P66', 'SHELL']
In [36]: list(map(str.title, L))
Out[36]: ['Chevron', 'Gunvor', 'P66', 'Shell']
In [37]: [s.title() for s in L]
Out[37]: ['Chevron', 'Gunvor', 'P66', 'Shell']
推荐阅读
- javascript - 在 React JS 中导入数组函数后无法检索我的电影数据
- google-maps - 如何访问谷歌地图中某个地点的事件数据?
- tensorflow - CLion中张量流的C++代码样式自动格式化?
- python - 如何在 Python 中为其中包含多个对象/函数的行进行换行(续行)?
- windows - 为什么 Docker 服务停止?
- react-native - 找不到项目的匹配配置:react-native-firebase
- go - 如何使用 Go 文件中的 gpg 密钥加密文件?
- r - 用较小的 tibble 子集一个 tibble
- c# - Newtonsoft.Json.Linq.JToken.SelectToken 线程安全吗?
- vba - 如何使用 VBA 在 Access 的导航表单中选择要打开的替代选项卡