[3, 3, 3, 4, 4, 2]
Would be:
[ (3, 3), (4, 2), (2, 1) ]
The output should be sorted by highest count first to low
Try using a collections.Counter:
from collections import Counter data = [3,4,2,3,4,3] Counter(data).most_common()