Explore Courses Blog Tutorials Interview Questions

Explore Tech Questions and Answers

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

0 votes
by (18.4k points)

I have the function that creates a list of lists.  I have defined 3 values in my list. Each of these values contains a list of their own contains and the other 2 values contain a number and their availability like:

[['Product 0', False, ], ['Product 1', False, ], ['Product 2', False,]]

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 does not have to capability to check for values of lists inside of the list.

1 Answer

0 votes
by (36.8k points)

You can use the list of comprehension for this. Iterate your inner lists and extract your second value (True\False). Then use all to check all your 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

Want to be a master in Data Science? Enroll in this Data Science Courses 

Browse Categories