for_some(), for_all()?

aurora aurora00 at
Wed Sep 22 18:57:21 CEST 2004

I am trying to test a list to see if some or all elements pass a test. For  
example I can use reduce() to test if any element is 0.

>>> lst = [1,2,0,3]
>>> test = lambda x: x == 0
>>> reduce(operator.__or__,[test(x) for x in lst])

However I bet reduce() does not exploit the short circuit logic. Also it  
is a little clumsy to create another list to pass into reduce. Is there  
some equivalent of

   for_some(test, lst)
   for_all(test, lst)?

More information about the Python-list mailing list