Created
May 20, 2012 01:26
-
-
Save tsycho/2733139 to your computer and use it in GitHub Desktop.
Nested (infinite) dictionary in Python
This file contains 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
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