我已经在下面尝试过了。
import re
sentences = "Glitches happened happened happened. Things go back to normal again."
print([re.findall(r"(\w+)\s\1", s) for s in sentences.split('.')])
我想知道如何打印包含重复单词的整个句子。
最佳答案
作为解决方法,您可以尝试:
import re
sentences = "Glitches happened happened happened. Things go back to normal again. And once again again again."
print([s for s in sentences.split('.') if re.search(r"\b(\w+)\s+\1\b", s)])
结果:
['Glitches happened happened happened', ' And once again again again']
关于python - 使用正则表达式查找包含重复单词的句子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64870516/