How to split a string into a list?

后端 未结 9 2468
执念已碎
执念已碎 2020-11-21 04:32

I want my Python function to split a sentence (input) and store each word in a list. My current code splits the sentence, but does not store the words as a list. How do I do

9条回答
  •  天命终不由人
    2020-11-21 05:05

    If you want all the chars of a word/sentence in a list, do this:

    print(list("word"))
    #  ['w', 'o', 'r', 'd']
    
    
    print(list("some sentence"))
    #  ['s', 'o', 'm', 'e', ' ', 's', 'e', 'n', 't', 'e', 'n', 'c', 'e']
    

提交回复
热议问题