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
1 2 | freq = [ 'a' , 1 , 'a' , 4 , 3 , 2 , 'a' ].count( 'a' ) print (freq) |
Output
1 | 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 Add Two Matrices
Python Keywords and Identifiers
Python print()
Python Program to Check if a Number is Positive, Negative or 0
Machine Learning with Python for everyone - Mark E.Fenner
Python Set clear()
Python Program to Print Colored Text to the Terminal
Python Shallow Copy and Deep Copy
Python Program to Check Leap Year
Python Program to Find Factorial of Number Using Recursion
Python Program to Check If Two Strings are Anagram
Python Program to Safely Create a Nested Directory
Python delattr()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Debug a JavaMail Program
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Find Sum of Natural Numbers Using Recursion
Python Program to Append to a File
Python time Module
Python getattr()
Python setattr()
Python String translate()
Python round()
Python Program to Convert Kilometers to Miles
Python int()
Python String isalnum()
Python Program to Find ASCII Value of Character
Python bytes()
Python Dictionary pop()
Python Program to Print Hello world!
Python del Statement
Python reversed()