简体   繁体   English

如何检查具有一系列项目的列表是否存在于另一个列表中

[英]How do I check if a list with a range of items exists in another list

Trying to figure out how to check if 1 of any number of lists is in a sublist - without doing it manually.试图弄清楚如何检查任意数量的列表中的 1 个是否在子列表中 - 无需手动进行。

The lists I'm checking for look like this:我正在检查的列表如下所示:

[10, ANY VALUE, ANY VALUE] [10,任何值,任何值]

The values should be between 0 - 120. So some of the values can be.这些值应该在 0 - 120 之间。所以有些值可以。

[10, 1, 4]
[10, 1, 2]
[10, 0, 0]

etc... ETC...

Here is an example of the list I want to find it in:这是我要在其中找到它的列表的示例:

items = [[3, 5, 0], [10, 1, 0], [10, 127, 127], [22, 4, 0], [22, 125, 127]]

So this would pull out [10, 1, 0]所以这会拉出[10, 1, 0]

Ideally it needs to work with an if in statement which looks like this:理想情况下,它需要使用如下所示的 if in 语句:

if [10, 127, 127] in items and [10, ANY, ANY] in items:
    # do something

You can use the any() function:您可以使用any() function:

if [10, 127, 127] in items and any(len(x) == 3 and x[0] == 10 for x in items):

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

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