Python Program to Count the Occurrence of an Item in a List – 2024

Hey guys, in this blog we will see a Python Program to Count the Occurrence of an Item in a List.

Using count() method

#Python Program to Count the Occurrence of an Item in a List

my_list = ['machine', 'learning', 'projects', 4, 'learning', 3, 'learning', 2, 'learning']
freq = my_list.count('learning')

print(freq)

Output

4

  • In the first step, we have defined a list.
  • In the second step, we used the list.count(item) method which will count the frequency of that item in the list.
  • Then we are simply printing the frequency.

Check out our other python programming examples

Abhishek Sharma
Abhishek Sharma

Started my Data Science journey in my 2nd year of college and since then continuously into it because of the magical powers of ML and continuously doing projects in almost every domain of AI like ML, DL, CV, NLP.

Articles: 520

Subscribe to our Newsletter

Subscribe to our newsletter and receive all latest projects...

Leave a Reply

Your email address will not be published. Required fields are marked *