any() and all() on empty list?

Paul McGuire ptmcg at
Wed Mar 29 08:45:20 CEST 2006

"Paul Rubin" <> wrote in message
news:7x3bh1x0ym.fsf at
> "Steve R. Hastings" <steve at> writes:
> > 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 goes against the usual meaning of "all" in, say, mathematical logic.
> Usually, "for all X in S, PRED(x) is true" means:
> there does not exist X in S so that PRED(x) is false.
How do you get this "usually" stuff?  I would agree that this is usually
implemented as a short-circuited loop through the list, that breaks out at
the first False value.  But I would not be quick to equate "commonality of
implementation" with "meaning".

> So, all(empty sequence) should be true.
"should be"? Or "usually turns out to be"?

To my mind, the *meaning* of all() is that every element in the list asserts
True.  But this is with an initial assumption that all() is False, unless I
test every value and find them to be True.  Since I assume False to begin
with, I get no values in the list to contradict the assumption, and so
all([]) returns False.

It would seem that the resolution rests on which initial condition we
choose, False or True.  Perhaps we should consult a more formal mathematical
resource for this.

-- Paul
"If it was so, it might be; and if it were so, it would be; but as it isn't,
it ain't. That's logic."

More information about the Python-list mailing list