Skip to content

Instantly share code, notes, and snippets.

@DuaneR5280
Last active December 15, 2021 23:57
Show Gist options
  • Save DuaneR5280/a569b7c6888d60043c5aeae1b550bdd5 to your computer and use it in GitHub Desktop.
Save DuaneR5280/a569b7c6888d60043c5aeae1b550bdd5 to your computer and use it in GitHub Desktop.
Sort python dictionary by key
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