[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
You can use a Counter in Python 2.7+ (this recipe works on 2.5+):
from collections import Counter print Counter([3, 3, 3, 4, 4, 2]).most_common() # [(3, 3), (4, 2), (2, 1)]