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 List copy()
Python Anonymous / Lambda Function
Python Sets
Python String strip()
Python String zfill()
Python Set isdisjoint()
Python complex()
Python frozenset()
Python Numbers, Type Conversion and Mathematics
Python String index()
Python Program to Get the Class Name of an Instance
Python String rsplit()
Python len()
Python Recursion
Python locals()
Python ascii()
Python Program to Check Prime Number
Python Program to Convert Kilometers to Miles
Python Dictionary setdefault()
Python Program to Check If a String Is a Number (Float)
Python Statement, Indentation and Comments
Python Program to Display Powers of 2 Using Anonymous Function
Python all()
Python Program to Differentiate Between del, remove, and pop on a List
Deep Learning with Python - Francois Cholletf
Python RegEx
Python String isidentifier()
Deep Learning with Python - Francois Chollet
Python compile()
Python Program to Copy a File
Python Dictionary update()
Python Set symmetric_difference()