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 format()
Python Program to Display the multiplication Table
Python Dictionary update()
Python String split()
Python File I/O Operation
Python Program to Sort a Dictionary by Value
Python range()
Python Program to Catch Multiple Exceptions in One Line
Python String splitlines()
Python @property decorator
Python Set issubset()
Python String rfind()
Python Program to Check Leap Year
Python Decorators
Python String istitle()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python Sets
Python issubclass()
Python String rindex()
Python tuple()
Python Program to Reverse a Number
Python open()
Python Input, Output and Import
Python Set pop()
Python dir()
Python Program to Illustrate Different Set Operations
Python Dictionary get()
Python List clear()
Python Inheritance
Python Set difference()
Python String isspace()
Python Program to Convert Decimal to Binary Using Recursion