简体   繁体   English

如何返回两个列表之间的不匹配

[英]How to return not matches between two lists

I have two lists, each with several elements in them:我有两个列表,每个列表中都有几个元素:

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']

I would like to use list comprehension to return not matches between the two lists.我想使用列表理解来返回两个列表之间的不匹配。 This is what I've tried:这是我尝试过的:

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

output: output:

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

I don't think I am using the list comprehension correctly but am unsure how to print a non-match, any ideas?我认为我没有正确使用列表理解,但不确定如何打印不匹配的内容,有什么想法吗? Thanks!谢谢!

I think you're looking for any built-in function of python:我认为您正在寻找 python 的any内置 function :

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

Output: Output:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM