Created
October 15, 2015 10:54
-
-
Save internetimagery/39d3f9bd9ce1950eaa3a to your computer and use it in GitHub Desktop.
nested dict
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
# http://stackoverflow.com/questions/635483/what-is-the-best-way-to-implement-nested-dictionaries-in-python/19829714#19829714 | |
class Dict(dict): | |
def __missing__(s, k): | |
v = s[k] = type(s)() | |
return v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment