Reputation: 780
Let's say Im storing a boolean value in list with a variable called save_status
I will be storing it like this
[ True, False, True, ...]
I want to be able to apply an and
to all the elements of the list like so:
True and False and True
, so that I know when all the elements of the list were True
Upvotes: 2
Views: 65
Reputation: 16950
Trying another way:
>>> all_true = [ True, True, True]
>>> mix = [ True, False, True]
>>> sum(all_true) == len(all_true)
True
>>> sum(mix) == len(mix)
False
>>>
Upvotes: 1
Reputation: 810
Use all
for "and" and any
for "or":
>>> my_list = [ True, False, True ]
>>> all(my_list)
... False
>>> any(my_list)
... True
Upvotes: 4