How to split a list of text into a list of words Python
本问题已经有最佳答案,请猛点这里访问。
我有这个清单:
1 | ["This is a set of words and it is not correct"] |
我想这样做:
1 | ["This","Is","A"] ... |
号
我该怎么做
1 | "This is a set of words and it is not correct".title().split() |
。
输出:
1 | ['This', 'Is', 'A', 'Set', 'Of', 'Words', 'And', 'It', 'Is', 'Not', 'Correct'] |
你可以这样做。
1 2 | a ="This is a set of words and it is not correct" [i.capitalize() for i in a.split()] |
如果输入是您在问题中提到的
1 2 | 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',
'Correct']
号
使用
1 2 3 | >>> 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'] |