Reputation: 31
So basically I have a function that creates a list of lists, lets say I define 3 values to be in my list and each of those 3 values has a list of their own that contains 2 values, their number, and their availability, like so:
[['Product 0', False, ], ['Product 1', False, ], ['Product 2', False,]]
Basically, I want to determine whether all values for availability are True
or False
, and I cannot seem to get it to work with all()
as it apparently does not have to capability to check for values of lists inside of a list.
Upvotes: 2
Views: 874
Reputation: 11342
You can use list comprehension for this. Iterate the inner lists and extract the second value (True\False). Then use all
to check all the values.
x = [['Product 0', False, ], ['Product 1', False, ], ['Product 2', False,]]
AllTrue = all([e[1] for e in x]) # False
AllFalse = all([not e[1] for e in x]) # True
Upvotes: 5