I have the following code (a list of tuples):
x = [(None, None, None), (None, None, None), (None, None, None)]
How would I know that this essentially evaluates to False
?
In other words, how could I do something like:
if not x: # x should evaluate to False
# do something
Use nested any()
calls:
if not any(any(inner) for inner in x):
any()
returns False
only if all of the elements in the iterable passed to it are False
. not any()
thus is True
only if all elements are false:
>>> x = [(None, None, None), (None, None, None), (None, None, None)]
>>> not any(any(inner) for inner in x)
True
>>> x = [(None, None, None), (None, None, None), (None, None, 1)]
>>> not any(any(inner) for inner in x)
False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With