short-circuiting any/all ?
Tim Wintle
tim.wintle at teamrubber.com
Mon Mar 22 11:12:52 EDT 2010
On Mon, 2010-03-22 at 14:45 +0000, kj wrote:
> I have a list of items L, and a test function is_invalid that checks
> the validity of each item. To check that there are no invalid
> items in L, I could check the value of any(map(is_invalid, L)).
> But this approach is suboptimal in the sense that, no matter what
> L is, is_invalid will be executed for all elements of L,
any( is_invalid(a) for a in L )
... generator expression will be lazily computed.
Tim
More information about the Python-list
mailing list