any() and all() on empty list?
Steven D'Aprano
steve at REMOVEMEcyber.com.au
Thu Mar 30 03:46:47 EST 2006
Tim Peters wrote:
>>In the all() example, if there *are* no values in S, then none of the
>>values can be != 0, and IMHO all() should return False.
>
>
> That would break everything mentioned above. Think of it another way:
> if all(seq) is false, shouldn't it be the case that you can point to
> a specific element in seq that is false?
Think of it this way: if all(seq) is true, shouldn't it
be the case that you can point to a specific element in
seq that is true?
It may be that all([]) => True is useful more often
than all([]) => False would be, in the same way that it
is useful to define 0! = 1 and other mathematical
identities, but that doesn't imply that, strictly
speaking, there isn't some monkey-business going on there.
Now, I'm happy to admit that this is useful
monkey-business, but it can still lead to unexpected
results, as in my example in a previous post.
--
Steven.
More information about the Python-list
mailing list