Arrange elements with same count in alphabetical order – Python Counter

By stfd1123581321

Python Collection Counter.most_common(n) method returns the top n elements with their counts. Elements with equal counts are ordered arbitrarily. So,

>>> Counter('AAABBBCCD').most_common(3)
[('B', 3), ('A', 3), ('C', 2)]

How can I change that to returning elements in alphabetical orders if two elements have the same quantity? So, expected output for the above input string should be:

[('A', 3), ('B', 3), ('C', 2)]

Source: Stack Overflow

    

Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273