Ich habe diese Liste teilen:Wie eine Liste von Text in eine Liste von Wörtern Python
["This is a set of words and it is not correct"]
Ich möchte es so machen:
["This", "Is", "A"] ...
Wie kann ich das tun
Ich habe diese Liste teilen:Wie eine Liste von Text in eine Liste von Wörtern Python
["This is a set of words and it is not correct"]
Ich möchte es so machen:
["This", "Is", "A"] ...
Wie kann ich das tun
Sie können so tun.
a = "This is a set of words and it is not correct"
[i.capitalize() for i in a.split()]
wenn der Eingang ist list
wie Sie in Ihrer Frage erwähnt.
a = ["This is a set of words and it is not correct"]
[i.capitalize() for i in a[0].split()]
Ausgabe
[ 'Das', 'I', 'A', 'Set', 'Von', 'Worten', 'Und', 'Es', " ist, 'Nicht', 'Correct']
Verwenden Sie die split()
Methode
>>> 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']
"This is a set of words and it is not correct".title().split()
Ausgabe:
['This', 'Is', 'A', 'Set', 'Of', 'Words', 'And', 'It', 'Is', 'Not', 'Correct']
'str.title' ist ziemlich süß. – erip
Wollen Sie auf beliebigen Leerzeichen aufteilen oder nur ein einzelnes '“ „'? – erip
Bitte googlen Sie dies: "Teilen Sie einen Satz in Worte" http://stackoverflow.com/questions/743806/split-string-into-a-list-in-python –
Sie schreiben einige Python-Code. – jonrsharpe