我对python很陌生,试图找到tweet是否有任何查找元素。使用字符串以任意顺序匹配数组元素
例如,如果我能找到这个单词猫,它应该匹配猫,也可以任意顺序匹配可爱的小猫。但从我了解我无法找到解决方案。任何指导表示赞赏。
import re
lookup_table = ['cats', 'cute kittens', 'dog litter park']
tweets = ['that is a cute cat',
'kittens are cute',
'that is a cute kitten',
'that is a dog litter park',
'no wonder that dog park is bad']
for tweet in tweets:
lookup_found = None
print re.findall(r"(?=(" + '|'.join(lookup_table) + r"))", tweet.lower())
输出
['cat']
[]
[]
['dog litter park']
[]
预期输出:
that is a cute cat > cats
kittens are cute > cute kittens
this is a cute kitten > cute kittens
that is a dog litter park > dog litter park
no wonder that dog park is bad > dog litter park
?? ??使用单数形式。 –
你也应该告诉我们你实际需要的输出。 –
@KarolyHorvath我不确定你的意思是 – user6083088