Skip to content

Instantly share code, notes, and snippets.

@AColocho
Created February 11, 2021 16:57
Show Gist options
  • Save AColocho/1cac537de07ccdf2e029a0c76ab79047 to your computer and use it in GitHub Desktop.
Save AColocho/1cac537de07ccdf2e029a0c76ab79047 to your computer and use it in GitHub Desktop.
One liner to order a dictionary by value or key.
#source https://stackoverflow.com/questions/613183/how-do-i-sort-a-dictionary-by-value
#Replace x with the dictionary name
#If ordering by value item[1] else item[0]
{k: v for k, v in sorted(x.items(), key=lambda item: item[1])}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment