我在试着从我的短信中提取相关信息。
我现在正在使用python。
(如有的话)(如在我的名单中):
搜索太多无关的字符串,
我正在寻找字符串,其中包含两个或更多的单词从我的名单。
因此,我的问题是:“我如何才能从清单中选择包含两个或两个以上单词的句子?”
谢谢你的帮助!
祝你今天愉快!
发布于 2017-07-09 23:06:32
1)拆分字符串。
2)检查文本中关键字的出现情况。
3)如果计数大于或等于2,则打印文本
keywords = ['the', 'apple' , 'fruit']
text = ['apple is a fruit', 'orange is fruit', 'the apple', 'the orange', 'the orange fruit']
for element in text:
if len(set(keywords)&set(element.split())) >=2 :
print element
输出:
apple is a fruit
the apple
the orange fruit
发布于 2017-07-09 22:21:13
我没有得到你想要的,但我理解的是:
list = ["This is tesing", "hello","My name", "This is not test"]
for sentense in list :
if len(sentense.split()) >= 2:
print sentense
输出:
This is tesing
My name
This is not test
希望这能帮到你..。
https://stackoverflow.com/questions/45004916
复制相似问题