Count The Number Of Occurrences In Python List
Published on September 24 2021
In this tutorial, you will learn a python program to count the number of occurrence in a list. We will do so by searching a element in a list using for loop in python and returning total count from the function.
Source code
list = [7,2,3,4,1,15,3]
Search = 3
def searchOccurance(list, number):
count = 0
for i in list:
if(i == number):
count+=1
return count
result = searchOccurance(list, Search)
if(result > 0):
print('Count is : ', result)
else:
print('Element not fount in the list.')
print('using Inbuilt function : ', list.count(Search))
Video
Next Tutorial
- Count The Number Of Occurrences In Python List
- Second Largest Number In A Python List