In this post, We will learn about how to count the frequency of elements of a tuple.
Implementation:
print("Enter number separated by comma")
t1=tuple([int(e) for e in input().split(',')])
i=0
for e in t1:
if i==t1.index(e):
print(e,' - ',t1.count(e))
i+=1
Output:
100,200,300,10,450,150,200,300,200,200,450,400,500,100,500,600,600,450
100 - 2
200 - 4
300 - 2
10 - 1
450 - 3
150 - 1
400 - 1
500 - 2
600 - 2
Happy Coding!
Follow us on Instagram @programmersdoor
Join us on Telegram @programmersdoor
Please write comments if you find any bug in the above code/algorithm, or find other ways to solve the same problem.
Follow Programmers Door for more.
Commentaires