any() and all() on empty list?

Carl Banks invalidemail at aerojockey.com
Fri Mar 31 03:00:53 CEST 2006


Steven D'Aprano wrote:
> On Thu, 30 Mar 2006 11:28:54 -0800, Paul Rubin wrote:
>
> > Steven D'Aprano <steve at REMOVEMEcyber.com.au> writes:
> >> > No, all(seq) is true if you can't point to a specific element in seq
> >> > that's false.
> >>
> >> No, all(seq) is true if every element in seq is true. Surely that's a
> >> more intuitive definition than your definition by what you can't do.
> >
> > They are different?
>
> Of course they are different -- they differ in the case of an empty
> sequence.

No, they're not.

Look, there are significant differences between natural and computer
languages, and in this case something is happening in the natural
language that isn't happening in this computer language.

In English, if I were to ask you a question like "Have you put all your
books in the truck?" when you have no books, a valid and reasonable
answer is "I don't have any books."  I.e., the answer is neither yes
nor no.  In fact, yes and no aren't valid answers at all (unless you're
being snarky**), because, in English, the word "all" carries an
assumption of existence.  (Or maybe it doesn't for you guys in
Australia; it does in the USA.)

In Python, yes and no are the only possible answers.  Probably the only
analogous thing you could do in Python would be for all() to raise
ValueError when passed an empty sequence.


Carl Banks

** - and note that, if you are being snarky, you would say "yes".




More information about the Python-list mailing list