我有这个清单:
["This is a set of words and it is not correct"]
我想这样做:
["This", "Is", "A"] ...
我该怎么做
答案 0 :(得分:3)
"This is a set of words and it is not correct".title().split()
输出:
['This', 'Is', 'A', 'Set', 'Of', 'Words', 'And', 'It', 'Is', 'Not', 'Correct']
答案 1 :(得分:1)
你可以这样做。
a = "This is a set of words and it is not correct"
[i.capitalize() for i in a.split()]
如果您在问题中提到的输入为list
。
a = ["This is a set of words and it is not correct"]
[i.capitalize() for i in a[0].split()]
<强>输出强>
['This','Is','A','Set','Of','Words','and','It','Is','Not', '正确的']
答案 2 :(得分:0)
使用split()
方法
>>> foo = ["This is a set of words and it is not correct"]
>>> foo[0].split()
['This', 'is', 'a', 'set', 'of', 'words', 'and', 'it', 'is', 'not', 'correct']