How to sort Counter by value? – python
Use the Counter.most_common() method, it’ll sort the items for you: >>> from collections import Counter >>> x = Counter({‘a’:5, ‘b’:3, ‘c’:7}) >>> x.most_common() [(‘c’, 7), (‘a’, 5), (‘b’, 3)] It’ll do so in the most efficient manner possible; if you ask for a Top N instead of all values, a heapq is used instead of … Read more