【发布时间】:2019-06-22 20:16:12
【问题描述】:
这是给定John plays chess and l u d o. 的输入我希望输出采用这种格式(如下所示)
John plays chess and ludo.
我尝试了正则表达式来删除空格 但对我不起作用。
import re
sentence='John plays chess and l u d o'
sentence = re.sub(r"\s+", "", sentence, flags=re.UNICODE)
print(sentence)
我期望输出 John plays chess and ludo. 。
但是我得到的输出是Johnplayschessandludo
【问题讨论】:
-
由于该表达式删除了所有空格,您是否只想删除单个字符周围的空格?
-
是的,先生。@DeveshKumarSingh
标签: python python-3.x text-mining spacy removing-whitespace