News for hackers. Stuff that matters.
Re:Widely useful Python utilities by Peter Norvig by knome on Monday September 14, 2009 @04:41PM (#822569)
If you have enough elements to desire short circuit evaluation you can, as `masklinn` mentioned, use a list comprehension. Specifically a generator list comprehension.

http://www.python.org/dev/peps/pep-0289/

    big_list = make_big_list()
    if any( not prime( a ) for a in big_list ) :
      do_thing()
When you surround the list comprehension syntax with parenthesis instead of square brackets, either as a lone argument to a function or independently, you create a generator that will iterate once over the given data.

This allows for functions accepting sequences to short circuit without completing the function mapping.

There are no comments on this comment yet.