In this example, you will learn to count the occurrence of an item in a list.
To understand this example, you should have the knowledge of the following Python programming topics:
Using count() method
freq = ['a', 1, 'a', 4, 3, 2, 'a'].count('a')
print(freq)
Output
3
Using count() method, pass the item to be counted. As shown above, 'a' is passed, which gives the total number of occurrences of character 'a'.
You can learn more about count() at Python count().
Related posts:
Python Package
Python Program to Add Two Matrices
Python Function Arguments
Python Set pop()
Python max()
Python List copy()
Python String isspace()
Python oct()
Python Program to Check if a Number is Positive, Negative or 0
Python Program to Represent enum
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python isinstance()
Python iter()
Python Program to Differentiate Between type() and isinstance()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python divmod()
Python Program to Find the Factorial of a Number
Python Program to Check Armstrong Number
Python Program to Count the Number of Digits Present In a Number
Python set()
Python *args and **kwargs
Python Program to Get a Substring of a String
Python hex()
Python strptime()
Python Object Oriented Programming
Python format()
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Program to Access Index of a List Using for Loop
Python print()
Python input()
Python list()
Python Dictionary popitem()