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

Leave a Reply

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