Created
September 26, 2022 21:09
-
-
Save ZhouYang1993/19c806290434f690925e423527ad90ed to your computer and use it in GitHub Desktop.
Sorting a Python Dictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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