split string by arbitrary number of white spaces

后端 未结 6 1286
夕颜
夕颜 2021-01-17 11:07

I\'m trying to find the most pythonic way to split a string like

\"some words in a string\"

into single words. string.split(\' \')

6条回答
  •  不知归路
    2021-01-17 11:19

    The most Pythonic and correct ways is to just not specify any delimiter:

    "some words in a string".split()
    
    # => ['some', 'words', 'in', 'a', 'string']
    

    Also read: How can I split by 1 or more occurrences of a delimiter in Python?

提交回复
热议问题