Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

program to count the number of occurrences of a elementes in a list python

#Count the frequency of elements in a list using dictionary
l=eva1.l(input("Enter the list"))
d={}
print(l)
for i in l:
if i not in d:
d[i]=l.count(i)
else:
pass
print("Frequency of element:")

for i in d:
print(i,"-",d[i])
output:
Enter the list[1,5,8,7,5,6,3,2,4,7,5,1,]
[1, 5, 8, 7, 5, 6, 3, 2, 4, 7, 5, 1]
Frequency of element:
1 - 2
5 - 3
8 - 1
7 - 2
6 - 1
3 - 1
2 - 1
4 - 1
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #program #count #number #occurrences #elementes #list #python
ADD COMMENT
Topic
Name
5+7 =