Skip to content

Instantly share code, notes, and snippets.

@pykong
Last active November 13, 2017 22:07
Show Gist options
  • Save pykong/460998d2dca5b5f4a8418e6ba70738dc to your computer and use it in GitHub Desktop.
Save pykong/460998d2dca5b5f4a8418e6ba70738dc to your computer and use it in GitHub Desktop.
Use this logic instead of a sequence of key checks.
l0 = {}
l1 = l0.setdefault("key_l1", {})
l2 = l1.setdefault("key_l2", [])
l2.append("3")
{'key_l1': {'key_l2': ['3']}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment