Operator.countOf() is used for counting the number of occurrences of
a. It counts the number of occurrences of value.
Syntax : Operator.countOf(freq = a, value = b)
freq : It can be list or any other data type which store value
value : It is value for which we have to count the number of occurrences
Returns: Count of number of occurrences of value.
Example #1: Use
Operator.countOf() to count the number of occurrences of given value in a list.
Number of occurrence of b in arr1 = 2 Number of occurrence of e in arr1 = 0 Number of occurrence of 3 in arr = 3
Example #2: Use
Operator.countOf() to count the number of occurrences of given value in a dictionary.
Number of occurrence of three in dict = 3 Number of occurrence of one in dict = 2 Number of occurrence of four in dict = 0
Example #3: Use
Operator.countOf() to count the number of occurrences of given value in a tuples.
Number of occurrence of b in tuple1 = 2 Number of occurrence of e in tuple1 = 0 Number of occurrence of 3 in tuple = 3
- Python | Index of Non-Zero elements in Python list
- Python | Merge Python key values to list
- Reading Python File-Like Objects from C | Python
- MySQL-Connector-Python module in Python
- Python | Convert list to Python array
- Important differences between Python 2.x and Python 3.x with examples
- Python | Add Logging to Python Libraries
- Python | Add Logging to a Python Script
- Python | Sort Python Dictionaries by Key or Value
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Visualizing O(n) using Python
- zip() in Python
- Python | a += b is not always a = a + b
- try-except vs If in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.
Improved By : nidhi_biet