short-circuiting any/all ?

kj no.email at please.post
Mon Mar 22 14:30:34 EDT 2010


In <291d82b7-b13b-4f49-901c-8194f3e07598 at e7g2000yqf.googlegroups.com> nn <pruebauno at latinmail.com> 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.

~K



More information about the Python-list mailing list