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:
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python list()
Python del Statement
Python String split()
Python Program to Display Fibonacci Sequence Using Recursion
Python timestamp to datetime and vice-versa
Python Program to Create a Long Multiline String
Python String lstrip()
Python Functions
Python String find()
Python Set copy()
Python memoryview()
Python Program to Create a Countdown Timer
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Errors and Built-in Exceptions
Python Program to Find the Size (Resolution) of a Image
Python Program to Parse a String to a Float or Int
Python Program to Convert String to Datetime
Python open()
Python String isdecimal()
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python List extend()
Python Dictionary copy()
Python exec()
Python List copy()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Program to Check if a Number is Odd or Even
Python classmethod()
Python Variables, Constants and Literals
Python String istitle()
Python Program to Make a Flattened List from Nested List
Python for Loop