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.
[color=blue][color=green][color=darkred]
>>> lst = [1,2,0,3]
>>> test = lambda x: x == 0
>>> reduce(operator .__or__,[test(x) for x in lst])[/color][/color][/color]
True
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)
or
for_all(test, lst)?
example I can use reduce() to test if any element is 0.
[color=blue][color=green][color=darkred]
>>> lst = [1,2,0,3]
>>> test = lambda x: x == 0
>>> reduce(operator .__or__,[test(x) for x in lst])[/color][/color][/color]
True
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)
or
for_all(test, lst)?
Comment