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 setattr()
Python Program to Solve Quadratic Equation
Python frozenset()
Python String lstrip()
Python sorted()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Reverse a Number
Python String endswith()
Python Set issuperset()
Python String lower()
Python Function Arguments
Python String translate()
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python Program to Calculate the Area of a Triangle
Python Set intersection()
Python Program to Count the Number of Digits Present In a Number
Intelligent Projects Using Python - Santanu Pattanayak
Python break and continue
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python str()
Python repr()
Python Set discard()
Python Program to Illustrate Different Set Operations
Python Data Structures and Algorithms - Benjamin Baka
Python Program to Display Calendar
Python Program to Swap Two Variables
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Program to Display Powers of 2 Using Anonymous Function
Python Program to Create Pyramid Patterns
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Merge Mails