any() and all() on empty list?

Paul Rubin http
Fri Mar 31 19:29:00 EST 2006


Ron Adam <rrr at ronadam.com> writes:
> The 'not not S' is just a conversion to bool. Is the following less
> contorted to you?
> 
>  >>> bool([])
> False

Oh ok.  Yes, bool(S) is much less contorted than "not not S".

> 'Is all True' isn't the same as 'Has all True'.  As I said, I'm not
> questioning the mathematical meaning of the set relation 'is all
> True', but wondering weather or not an alternate relation 'has all
> True' would be better for use as a flow control test.
> 
> Do you have some examples uses since it's obvious to you?

    # go out drinking when I'm finished with today's work
    if all (task.done() for task in self.things_to_do_today()):
       self.go_out_drinking()

If I didn't have anything to do today, that should result in going out
drinking immediately.

> I just have a feeling we will see a lot of "S and all(S)" expressions
> being used.  Maybe that's not so bad,  but I would prefer to not have
> to do that if it turns out to the standard idiom for all testing
> within a loop.

I think "S and all(S)" is the right way to express that, if that's
what's intended.



More information about the Python-list mailing list