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 List sort()
Python oct()
Python List Comprehension
How to get current date and time in Python?
Python RegEx
Python Set pop()
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Program to Check Leap Year
Python Global, Local and Nonlocal variables
Python min()
Python *args and **kwargs
Python dir()
Python divmod()
Python any()
Python format()
Python String isnumeric()
Python tuple()
Python Exception Handling Using try, except and finally statement
Python round()
Python String encode()
Python Program to Convert Bytes to a String
Python Program to Slice Lists
Python slice()
Python float()
Python Dictionary keys()
Python String lower()
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Program to Display Powers of 2 Using Anonymous Function
Python frozenset()
Python Dictionary
Deep Learning with Python - Francois Chollet
Python Program to Get the Class Name of an Instance