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)]
1from collections import Counter
2
3def frequency_table(n):
4 table = Counter(n)
5 print('Number\tFrequency')
6 for number in table.most_common() :
7 print('{0}\t{1}'.format(number[0], number[1]))
8
9# src : Doing Math With Python