匹配字符串的完整单词与列表

匹配字符串的完整单词与列表

本文介绍了匹配字符串的完整单词与列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将完整句子的单词与单词列表进行匹配,如果不包含则继续下一步。但是,它也部分匹配。



例如,如果我的列表中包含单词'me',并且在句子中有一个单词'some'则会失败。



我尝试了什么:



我做了什么,



I want to match words of a complete sentence against a list of words, and if contain not to proceed to next step. However, it matches partially as well.

For example, if my list contain a word 'me' and in the sentence there is a word 'some' it fails.

What I have tried:

What I've done,

if not any(word in text_sentence.lower().strip() for word in banned_words):
    # Proceed to next level, as a valid sentence





一旦我通过像你一样的人它失败了,因为我的列表中包含一个单词我。验证只需打印单词。





Once I pass "Some one like you" it fails, as my list contain a word "me". Verified simply printing the words.

for item in banned_words:
    if item in slbot_tweet:
        print(item)

推荐答案



这篇关于匹配字符串的完整单词与列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 00:30