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 Set symmetric_difference()
Python Program to Check If Two Strings are Anagram
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Program to Capitalize the First Character of a String
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Program to Check If a String Is a Number (Float)
Python next()
Python String istitle()
Python Set difference()
Python Program to Convert Celsius To Fahrenheit
Python List clear()
Python Program to Iterate Over Dictionaries Using for Loop
Python Tuple
Python str()
Python String swapcase()
Python Anonymous / Lambda Function
Python Program to Display Calendar
Python Program to Check if a Number is Odd or Even
Python Program to Iterate Through Two Lists in Parallel
Python Set issubset()
Python Program to Compute all the Permutation of the String
Python locals()
Python Set clear()
Python frozenset()
Python bytes()
Python String rsplit()
Python if...else Statement
Python Program to Find the Factors of a Number
Python Machine Learning - Sebastian Raschka
Intelligent Projects Using Python - Santanu Pattanayak
Python Program to Print all Prime Numbers in an Interval
Python Program to Find the Largest Among Three Numbers