any(), all() and empty iterable

John O'Hagan mail at
Sun Apr 12 06:00:40 CEST 2009


I was getting some surprising false positives as a result of not expecting 

all(element in item for item in iterable)

to return True when 'iterable' is empty. 

I guess it goes into hairy Boolean territory trying to decide if an element is 
in an item that doesn't exist (if that's what's happening), but I would have 
thought not. It seems inconsistent with the behaviour of

any(element in item for item in iterable)

which returns False when 'iterable' is empty.

Sorry if this has come up before, but 'any' and 'all' make for fruitless 

Any light to be shed?



More information about the Python-list mailing list