Last active
December 15, 2021 23:57
-
-
Save DuaneR5280/a569b7c6888d60043c5aeae1b550bdd5 to your computer and use it in GitHub Desktop.
Sort python dictionary by key
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
from pprint import pprint | |
SM = { | |
"instagram": r"instagram.com", | |
"facebook": r"facebook.com", | |
"twitter": r"twitter.com", | |
"youtube": r"youtube.com", | |
"snapchat": r"snapchat.com" | |
} | |
sm_sorted_by_key = dict(sorted(SM.items(), key=lambda kv: (kv[1], kv[0])) | |
pprint(sm_sorted_by_key) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment