Skip to content

Instantly share code, notes, and snippets.

@asayers
Created February 15, 2013 22:00
Show Gist options
  • Save asayers/4963897 to your computer and use it in GitHub Desktop.
Save asayers/4963897 to your computer and use it in GitHub Desktop.
Accepts a dict and returns a list of the keys, ordered according to their values.
def rank(hash):
ranking = []
for v in set(sorted(hash.itervalues())):
ranking.extend([key for key, val in hash.items() if val == v])
return ranking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment