1import collections
2a = [1,1,1,1,2,2,2,2,3,3,4,5,5]
3counter=collections.Counter(a)
4print(counter)
5# Counter({1: 4, 2: 4, 3: 2, 5: 2, 4: 1})
6print(counter.values())
7# [4, 4, 2, 1, 2]
8print(counter.keys())
9# [1, 2, 3, 4, 5]
10print(counter.most_common(3))
11# [(1, 4), (2, 4), (3, 2)]
1freq = {}
2 for item in my_list:
3 if (item in freq):
4 freq[item] += 1
5 else:
6 freq[item] = 1