Created
July 18, 2016 06:34
-
-
Save gtalarico/50b6eea650d359fb99aac813853e44d5 to your computer and use it in GitHub Desktop.
json like python dict
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
def tree(): | |
return defaultdict(tree) | |
Adding a simple subclass allows attribute like selection: | |
class mydefaultdict(defaultdict): | |
def __getattr__(self, attr): | |
return self[attr] | |
def __setattr__(self, attr, val): | |
self[attr] = val | |
def tree(): return mydefaultdict(tree) | |
will turn: | |
taxonomy['Animalia']['Chordata']['Mammalia']['Carnivora']['Felidae']['Felis']['cat'] | |
into: | |
taxonomy.Animalia.Chordata.Mammalia.Carnivora.Felidae.Felis.cat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from:
https://gist.github.com/hrldcpr/2012250