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 del Statement
Python Program to Get Line Count of a File
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Dictionary popitem()
Python break and continue
Python Program to Generate a Random Number
Python tuple()
Python *args and **kwargs
Python Dictionary
Python globals()
Python min()
Python Set difference_update()
Python Program to Differentiate Between del, remove, and pop on a List
Python bin()
Python List extend()
Python Closures
Python Sets
Python Multiple Inheritance
Python Program to Find the Sum of Natural Numbers
Python Program to Trim Whitespace From a String
Python Inheritance
Python List sort()
Python Program to Check If a List is Empty
Python String isidentifier()
Python __import__()
Python Strings
Python Operator Overloading
Python String rstrip()
Python setattr()
Python Exception Handling Using try, except and finally statement
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Program to Remove Duplicate Element From a List