any(), all() and empty iterable

J

John O'Hagan

Hi,

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

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
googling!

Any light to be shed?

Regards,

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,242
Latest member
KendrickKo

Latest Threads

Top