counter increasing value sort code example
Example 1: python collections Counter sort by key
# Just use sorted()
from collections import Counter
counter = Counter({'A': 10, 'C': 5, 'H': 7})
counter.most_common()
>>>[('A', 10), ('H', 7), ('C', 5)]
sorted(counter.items())
>>>[('A', 10), ('C', 5), ('H', 7)]
Example 2: collections counter sort by value
>>> Counter('abracadabra').most_common(3)
[('a', 5), ('r', 2), ('b', 2)]