I have a list of Booleans:
[True, True, False, False, False, True]
and I am looking for a way to count the number of True
in the list (so in the example above, I want the return to be 3
.) I have found examples of looking for the number of occurrences of specific elements, but is there a more efficient way to do it since I'm working with Booleans? I'm thinking of something analogous to all
or any
.
True
is equal to 1
.
>>> sum([True, True, False, False, False, True])
3