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:
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Tuple
Python sum()
Python Program to Concatenate Two Lists
Python Program to Find HCF or GCD
Python bin()
Python Operators
Python Anonymous / Lambda Function
Python List remove()
Python Tuple count()
Python type()
Python int()
Python String rfind()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Copy a File
Python any()
Python Program to Get a Substring of a String
Python String istitle()
Python Program to Transpose a Matrix
Python Exception Handling Using try, except and finally statement
Python eval()
APIs in Node.js vs Python - A Comparison
Python List index()
Python String encode()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Program to Solve Quadratic Equation
Python __import__()
Python map()
Python Namespace and Scope
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Program to Make a Flattened List from Nested List
Python Directory and Files Management