Non-short-circuit variant of any/all
suggest changereduce does not stop before the iterable has been completely iterated, so it can be used as a non-short-circuit any() or all(). For bool values, operator.and_ and operator.or_ return bool:
import operator
from functools import reduce
# non short-circuit "all"
reduce(operator.and_, [False, True, True, True]) # = False
# non short-circuit "any"
reduce(operator.or_, [True, False, False, False]) # = True
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents