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 String strip()
Python complex()
Python Program to Print Output Without a Newline
Python oct()
Python Set update()
Python chr()
Python String split()
Python Program to Solve Quadratic Equation
Python pass statement
Python String isalpha()
Python String count()
Python eval()
Python String partition()
Python Program to Count the Number of Occurrence of a Character in String
Python Set clear()
Python sum()
Python Closures
Python String rstrip()
Python memoryview()
Python String maketrans()
Python hex()
Python Program to Print the Fibonacci sequence
Python time Module
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Program to Parse a String to a Float or Int
Python Program to Return Multiple Values From a Function
Python Program to Remove Duplicate Element From a List
Python filter()
Python del Statement
Python float()
Python Program to Create a Countdown Timer
Python Program to Illustrate Different Set Operations