How to count the frequency of each tuple in a list of tuples in Python

1 Answer

0 votes
from collections import Counter

tplList = [(4, 9, 0), (3, 4), (4, 9, 0), (4, 9, 0), (5), (1, 2), (3, 4)]

frequency = [(key, val) for key, val in Counter(tplList).items()]

print(frequency)



'''
run:

[((4, 9, 0), 3), ((3, 4), 2), (5, 1), ((1, 2), 1)]

'''

 



answered Dec 4, 2022 by avibootz
...