且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在列表和字符串中查找匹配的单词

更新时间:2022-02-07 21:20:36

您仍然必须至少检查所有内容,直到在文本中找到一个为止,但这可以更加简洁:

You still have to check them all at least until one is found to be in the text, but it can be more concise:

keyword_list = ['motorcycle', 'bike', 'cycle', 'dirtbike']

if any(word in all_text for word in keyword_list):
    print 'found one of em'