Last active
February 10, 2016 20:54
-
-
Save nomeyer/788e6d14238bb4b28517 to your computer and use it in GitHub Desktop.
Sort a dictionary by value (descending) – see http://stackoverflow.com/a/613218
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from operator import itemgetter | |
sorted_d = sorted(d.items(), key=itemgetter(1), reverse=True) | |
# sorted_dict is a list of tuples (key, value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment