[3, 3, 3, 4, 4, 2]
Would be:
[ (3, 3), (4, 2), (2, 1) ]
The output should be sorted by highest count first to lowest count. In this case, 3 to 2 to 1.
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)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With