Although using all
is one and preferably only obvious way to do it
in Python, here is another way to do the same with the and_ function from operator and reduce
>>> a = [True, True, False] >>> from operator import and_ >>> reduce(and_, a) False >>> b = [True, True, True] >>> reduce(and_, b) True
Edit: As mentioned by Duncan, and_
is the bitwise operator of &
, not the logical and
. It will only work for boolean values, since they will be passed to int (1 or 0)
Following the comments, you really need to use BIF all
to achieve what the OP asked. I wanted to add this as an answer because I find it useful sometimes, for example, for creating complex db queries in Django using Q objects and in some other cases.
source share