Given a list of booleans, write a Python program to find the count of true booleans in the given list.
Input : [True, False, True, True, False] Output : 3 Input : [False, True, False, True] Output : 2
Method #1 : Using List comprehension
One simple method to count True booleans in a list is using list comprehension.
Method #2 : Using
A more robust and transparent method to use sum is given below.
Method #3 :
Method #4 :
- Python | Get indices of True values in a binary list
- Python | Test if any list element returns true for condition
- Python program to fetch the indices of true values in a Boolean list
- Python | First occurrence of True number
- Python list function | count()
- Python | Find all elements count in list
- Count set bits using Python List comprehension
- Python | Count occurrences of an element in a list
- Python | Count the sublists containing given element in a list
- Python program to count Even and Odd numbers in a List
- Python | Count unique sublists within list
- Python | Program to count duplicates in a list of tuples
- Python | Count occurrence of all elements of list in a tuple
- Python | Count the elements in a list until an element is a Tuple
- Python | Count number of items in a dictionary value that is a list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.