I need to find the frequency of elements in an unordered list
a = [1,1,1,1,2,2,2,2,3,3,4,5,5]
output->
b =
Simple solution using a dictionary.
def frequency(l): d = {} for i in l: if i in d.keys(): d[i] += 1 else: d[i] = 1 for k, v in d.iteritems(): if v ==max (d.values()): return k,d.keys() print(frequency([10,10,10,10,20,20,20,20,40,40,50,50,30]))