split string by arbitrary number of white spaces

后端 未结 6 1344
夕颜
夕颜 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:18

    Just use my_str.split() without ' '.


    More, you can also indicate how many splits to perform by specifying the second parameter:

    >>> ' 1 2 3 4  '.split(None, 2)
    ['1', '2', '3 4  ']
    >>> ' 1 2 3 4  '.split(None, 1)
    ['1', '2 3 4  ']
    

提交回复
热议问题