拆分带有附加空格的Python字符串(句子)

nag*_*sic 1 python string whitespace split

可能会拆分一个Python字符串(句子),以便它保留输出中单词之间的空格,但是在一个拆分子字符串中,通过在每个单词后面附加它?

例如:

given_string = 'This is my string!'
output = ['This ', 'is ', 'my ', 'string!']
Run Code Online (Sandbox Code Playgroud)

erh*_*sto 5

我大部分时间都避免使用正则表达式,但这里它非常简单:

import re

given_string = 'This is my string!'
res = re.findall(r'\w+\W?', given_string)

# res ['This ', 'is ', 'my ', 'string!']
Run Code Online (Sandbox Code Playgroud)