Reputation: 642
Trying to figure out how to check if 1 of any number of lists is in a sublist - without doing it manually.
The lists I'm checking for look like this:
[10, ANY VALUE, ANY VALUE]
The values should be between 0 - 120. So some of the values can be.
[10, 1, 4]
[10, 1, 2]
[10, 0, 0]
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]
Ideally it needs to work with an if in statement which looks like this:
if [10, 127, 127] in items and [10, ANY, ANY] in items:
# do something
Upvotes: 0
Views: 58
Reputation: 33359
You can use the any()
function:
if [10, 127, 127] in items and any(len(x) == 3 and x[0] == 10 for x in items):
Upvotes: 1