I am having around 10 boolean variables, I need to set a new boolean variable x=True
if all those ten variable values are True.If one of them is False then set x= False
I can do this in a manner
if (a and b and c and d and e and f...):
x = True
else:
x=False
which obviously looks very ugly.Please suggest some more pythonic solutions.
The ugly part is a and b and c and d and e and f...
Assuming you have the bools in a list/tuple:
x = all(list_of_bools)
or just as suggested by @minopret
x= all((a, b, c, d, e, f))
example:
>>> list_of_bools = [True, True, True, False]
>>> all(list_of_bools)
False
>>> list_of_bools = [True, True, True, True]
>>> all(list_of_bools)
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With