Skip to content

Instantly share code, notes, and snippets.

@liudong
Created April 20, 2018 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liudong/22138f9af9261a0c72136ae28249a3c6 to your computer and use it in GitHub Desktop.
Save liudong/22138f9af9261a0c72136ae28249a3c6 to your computer and use it in GitHub Desktop.
Python: sort dict by values
import operator
x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
sorted_x = sorted(x.items(), key=operator.itemgetter(1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment