首页 > 解决方案 > 将列表中的所有术语转换为标题大小写

问题描述

我有一个清单:

['CHEVRON' 'GUNVOR' 'P66' 'SHELL']

我需要将它们转换为标题格式。

我目前正在遍历它们,但必须有一种更简单的方法。

预期输出:

['Chevron', 'Gunvor', 'P66', 'Shell']

标签: python

解决方案


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']

推荐阅读