# any() and all() on empty list?

Paul Rubin http
Thu Mar 30 21:28:54 CEST 2006

```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?  I'd say every element in seq is true, unless
there's an element that's false.  Do you want to pick a different word
than "all" and suggest renaming the function?

> Here's another way of looking at the problem:
>
> all(flying elephants which are pink) => true
> all(flying elephants which are not pink) => true
>
> So, these flying elephants -- are they pink or not?

By the definition, "all flying elephants are pink" and "all flying
elephants are non-pink" are both true statements, if that's what
questions like "have you stopped beating your wife".

I'd say:

def boolify(s): return map(bool, s)

then:

all(S) = reduce(operator.and_, boolify(S), True)
any(S) = reduce(operator.or_, boolify(S), False)

You can see that changing True to False in the above definition of all
would make the result always false.

FWIW, I threw all my TV sets off the roof of my building this morning.
But nobody on the sidewalk needed to worry about getting hit by one ;-).

```