Skip to content

Instantly share code, notes, and snippets.

@tsycho
Created May 20, 2012 01:26
Show Gist options
  • Save tsycho/2733139 to your computer and use it in GitHub Desktop.
Save tsycho/2733139 to your computer and use it in GitHub Desktop.
Nested (infinite) dictionary in Python
class NestedDict(dict):
def __getitem__(self, key):
if key in self: return self.get(key)
return self.setdefault(key, NestedDict())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment