def count(x,s): count=0 for i in range(len(x)): if s == x[i]: count=count+1 x[i] = None return [s,count] def mode(x): x.sort() tags = [] highmode = [[None,None],None] for i in range(len(x)): if(x[i] != None): foo = count(x,x[i]) tags = tags + [foo] return tags print mode([1,1,2,5,5,2])