Skip to content
scipython.com

Q2.4.5any(x) and not all(x)

For what iterable sequences, x, does the expression

any(x) and not all(x)

evaluate to True?

Show solution

any(x) and not all(x) is True if at least one item in x is equivalent to True but not all of them:

>>> x1, x2, x3 = [False, False], [1, 2, 3, 4], [1, 2, 3, 0]
>>> any(x1) and not all(x1)
False
>>> any(x2) and not all(x2)
False
>>> any(x3) and not all(x3)
True