Skip to content

Instantly share code, notes, and snippets.

@nomeyer
Last active February 10, 2016 20:54
Show Gist options
  • Save nomeyer/788e6d14238bb4b28517 to your computer and use it in GitHub Desktop.
Save nomeyer/788e6d14238bb4b28517 to your computer and use it in GitHub Desktop.
Sort a dictionary by value (descending) – see http://stackoverflow.com/a/613218
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