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 Program to Extract Extension From the File Name
Python Program to Display the multiplication Table
Python Program to Access Index of a List Using for Loop
Python Program to Get Line Count of a File
Python String rsplit()
Python hasattr()
Deep Learning with Python - Francois Cholletf
Python Dictionary keys()
Python String expandtabs()
Python Program to Find LCM
Python dir()
Python callable()
Python String split()
Python Program to Iterate Through Two Lists in Parallel
Python format()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Dictionary pop()
Python Program to Check if a Number is Odd or Even
Python Data Structures and Algorithms - Benjamin Baka
Python datetime
Python max()
Python Program to Get the Full Path of the Current Working Directory
Python Set issubset()
Python Set update()
Python RegEx
Python Program to Check if a Key is Already Present in a Dictionary
Python Program to Check Armstrong Number
Python Program to Print the Fibonacci sequence
Python timestamp to datetime and vice-versa
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python input()
Python Type Conversion and Type Casting