Python中的单词匹配 [英] Word matching in Python
本文介绍了Python中的单词匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个,但是它正在做部分匹配:
I have this but it's doing partial matching:
for il in ignore_list:
if il.word in title or il.word in text:
return True
我怎么只能匹配整个单词?
How can I only match whole words?
推荐答案
您需要将标题和文本字符串分成单词列表:
You need to split your title and text strings into lists of words:
if il.word in title.split() or il.word in text.split():
这篇关于Python中的单词匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文