python collections counter sort by key

Solutions on MaxInterview for python collections counter sort by key by the best coders in the world

showing results for - "python collections counter sort by key"
Alycia
07 Jan 2020
1# Just use sorted()
2from collections import Counter
3counter = Counter({'A': 10, 'C': 5, 'H': 7})
4counter.most_common()
5>>>[('A', 10), ('H', 7), ('C', 5)]
6sorted(counter.items())
7>>>[('A', 10), ('C', 5), ('H', 7)]