如何 return 不匹配两个列表

How to return not matches between two lists

我有两个列表,每个列表中都有几个元素:

list_2 = ['https://josh.ucc.edu/just-go-grind-125/','https://josh.ucc.edu/thirty-minute-kayak-2/', 'https://josh.ucc.edu/fight-online-t-shirts-help-support-local-businesses/']
matchers = ['just-go-grind', 'thirty-minute']

我想使用列表理解来 return 两个列表之间的不匹配。这是我试过的:

not_matching = [s for s in list_2 if None(xs in s for xs in matchers)]
print(not_matching)

输出:

not_matching = [s for s in list_2 if None(xs in s for xs in matchers)]]
                                                                       ^
SyntaxError: invalid syntax

我认为我没有正确使用列表理解,但不确定如何打印不匹配项,有什么想法吗?谢谢!

我认为您正在寻找 python 的 any 内置函数:

not_matching = [s for s in list_2 if not any(xs in s for xs in matchers)]

输出:

not_matching
['https://josh.ucc.edu/fight-online-t-shirts-help-support-local-businesses/']