split string by arbitrary number of white spaces

后端 未结 6 1284
夕颜
夕颜 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条回答
  •  梦毁少年i
    2021-01-17 11:27

    How about:

    re.split(r'\s+',string)
    

    \s is short for any whitespace. So \s+ is a contiguous whitespace.

提交回复
热议问题