50 - Write a program in Python to count the frequency of all elements of a list.
L= [10, 20, 30, 20, 40, 30, 20, 50]
print("List is: ",L)
Uni= []
Freq= []
for i in L:
if i in Uni:
index=Uni.index(i)
Freq[index]+= 1
else:
Uni.append(i)
Freq.append(1)
for i in range(len(Uni)):
print(Uni[i],":",Freq[i])
Output:
List is: [10, 20, 30, 20, 40, 30, 20, 50]
10 : 1
20 : 3
30 : 2
40 : 1
50 : 1
No comments:
Post a Comment