split string by arbitrary number of white spaces

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

    text = "".join([w and w+" " for w in text.split(" ")])
    

    converts large spaces into single spaces

提交回复
热议问题