short-circuiting any/all ?

kj at
Mon Mar 22 19:30:34 CET 2010

In <291d82b7-b13b-4f49-901c-8194f3e07598 at> nn <pruebauno at> writes:

>If you are in Python 3 "any(map(is_invalid, L))" should short circuit.
>If you are in Python 2 use "from itertools import imap;
>any(imap(is_invalid, L))"

Thanks!  I'm glad to know that one can get the short circuiting
using a map-type idiom.  (I prefer map over comprehensions when I
don't need to define a function just for the purpose of passing it
to it.)

And thanks also to the other repliers for pointing out that the
comprehension version does what I was asking for.


More information about the Python-list mailing list