In a conditional like if (bool) and (bool):, what is the cleanest expression that will return True if both evaluations are False?
I see many options to logically make this work, but they all look messy to me.
In a conditional like if (bool) and (bool):, what is the cleanest expression that will return True if both evaluations are False?
I see many options to logically make this work, but they all look messy to me.
You can either use all:
if all(not b for b in [bool_1, bool_2, ..., bool_n]):
# means: if all are not True (False)
any:
if not any([bool_1, bool_2, ..., bool_n]):
# means: if not any of them is True (same as above, logically)
Or, sum (only with bool type, otherwise use sum(map(bool, [bool_1, ..., bool_n]))):
if sum([bool_1, bool_2, ..., bool_n]) == 0: # or, if not sum(...):
# True is 1, False is 0, if sum is 0, then all are 0 (False)