3 ms·
By itself, yes, but >>> all([[[]]]) == True True >>> all([[]]) == True False >>> all([]) == True True is pretty counter-intuitive at first glance.
by agf 11y ago
By itself, yes, but
>>> all([[[]]]) == True
True
>>> all([[]]) == True
False
>>> all([]) == True
True
is pretty counter-intuitive at first glance.
- pvdebbe 11y agoAt first glance, yes. Needs a moment to think this through. But not a wat because this works exactly as the logic says. If we denote x = [] then bool(x) == False # empty list is falsy bool([x]) == True # nonempty list is truthy bool([[x]]) == True # nonempty again and finally, [bool(elem) for elem in [[x]]] == [True] # all True! which is the thing `all' is interested in. It is more like a newbie mistake or careless document reading if the user thinks `all' runs through the lists and all of the nesting too.