Skip to content

Instantly share code, notes, and snippets.

@ZhouYang1993
Created September 26, 2022 21:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZhouYang1993/19c806290434f690925e423527ad90ed to your computer and use it in GitHub Desktop.
Save ZhouYang1993/19c806290434f690925e423527ad90ed to your computer and use it in GitHub Desktop.
Sorting a Python Dictionary
cities = {'London': '2', 'Tokyo': '3', 'New York': '1'}
print(sorted(cities.items(),key=lambda d:d[1]))
# [('New York', '1'), ('London', '2'), ('Tokyo', '3')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment