在Python中大写字符串数组中每个元素的最佳方法是什么?
此:
["a", "able", "about", "across", "after", "all"]
应该成为:
["A", "Able", "About", "Across", "After", "All"]
答案 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]