在Python中对字符串数组中的每个元素进行大写的最佳方法是什么?

时间:2015-03-06 01:17:16

标签: python

在Python中大写字符串数组中每个元素的最佳方法是什么?

此:

["a", "able", "about", "across", "after", "all"]

应该成为:

["A", "Able", "About", "Across", "After", "All"]

2 个答案:

答案 0 :(得分:3)

使用大写:

new_list = map(str.capitalize, old_list)

答案 1 :(得分:2)

使用str.title

words = ["a", "able", "about", "across", "after", "all"]
cap_words = [word.title() for word in words]