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 String split()
Python slice()
Python Errors and Built-in Exceptions
Python List index()
Python Exception Handling Using try, except and finally statement
Python isinstance()
Python hash()
Python hasattr()
Python property()
Python Program to Delete an Element From a Dictionary
Python Program to Capitalize the First Character of a String
Python for Loop
Python List count()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Anonymous / Lambda Function
Python Dictionary update()
Python complex()
Python Multiple Inheritance
Python Program to Convert Decimal to Binary Using Recursion
Python String format()
Python Set pop()
Python Program to Find Armstrong Number in an Interval
Python Custom Exceptions
Python break and continue
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python frozenset()
Python Program to Copy a File
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Closures
Python Program to Slice Lists
Node.js vs Python for Backend Development
Python bin()