1# easiest way to count the frequency of all elements in a list
2lst = ['Sam', 'Sam', 'Tim', 'Tim', 'Tim', 'r', 'l']
3
4freq = {} # stores the frequency of elements
5counting = [freq.update({x: lst.count(x)}) for x in lst]
6
7# output of freq
8{'Sam': 2, 'Tim': 3, 'r': 1, 'l': 1}
9
10#credit: buggyprogrammer.com
11#Note: if you print "counting" it will return a list full of None so ignore it.
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