检查列表中的任何字符串是否包含在另一个列表中的任何字符串中

Max*_*ung 2 python string substring list

我有一个新闻标题列表,想检查是否有标题包含列表中的任何关键字。

例如

newstitle =['Python is awesome', 'apple is tasty', 'Tom cruise has new movie']
tag = ['Python','Orange', 'android']
Run Code Online (Sandbox Code Playgroud)

tag如果in 中有任何关键字newstitle,我希望它返回True

我知道如何使用单个标签来做到这一点:

any('Python' in x for x in newstitle)
Run Code Online (Sandbox Code Playgroud)

但是如何使用多个关键字呢?

rok*_*rok 5

下面的代码应该可以达到要求:

any(t in x for x in newstitle for t in tag)

来自文档

列表推导式由包含表达式的括号组成,后跟 for 子句,然后是零个或多个 for 或 if 子句。结果将是一个新列表,该列表是在其后面的 for 和 if 子句的上下文中评估表达式而产生的。