【发布时间】:2020-01-05 09:36:14
【问题描述】:
我正在做一个主题建模任务,并且有以下形式的未知主题
topic = 0.2*"firstword" + 0.2*"secondword" + 0.2*"thirdword" + 0.2*"fourthword" + 0.2*"fifthword"
我想要一个 regex.findall() 函数返回一个仅包含单词的列表,例如:
['firstword', 'secondword', 'thirdword', 'fourthword', 'fifthword']
我尝试过使用正则表达式函数:
regex.findall(r'\w+', topic) and
regex.findall(r'\D\w+', topic)
但它们都不能正确消除数字。 有人可以帮我找出我做错了什么吗?
【问题讨论】:
-
什么是
topic?str? -
是的主题是'str'类型
-
@SoumyaChakraborty 你能分享
topic字符串的实际值吗?是'0.2*"firstword" + 0.2*"secondword" + 0.2*"thirdword" + 0.2*"fourthword" + 0.2*"fifthword"'吗? -
如果我输入 print(topic) 它会显示:0.2*"firstword" + 0.2*"secondword" + 0.2*"thirdword" + 0.2*"fourthword" + 0.2*"fifthword"