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 Global Keyword
Python input()
Deep Learning with Python - Francois Cholletf
Python locals()
Python String zfill()
Python String rfind()
Python Program to Check Leap Year
Python String capitalize()
Deep Learning in Python - LazyProgrammer
Python list()
Python break and continue
Python Inheritance
Python Program to Reverse a Number
Python Operators
Python Set discard()
Python Program to Check if a Number is Positive, Negative or 0
Python Dictionary update()
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Program to Check If Two Strings are Anagram
Python complex()
Python Program to Remove Duplicate Element From a List
Python String isalnum()
Python Generators
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python String isdigit()
Python Shallow Copy and Deep Copy
Python map()
Python memoryview()
Python repr()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python hasattr()
Python List extend()