>> nested_dd = collections.defaultdict(lambda: nested_dd)
>> nested_dd['a']['b']['c']['d'] = 'hello' >> nested_dd = collections.defaultdict(lambda: nested_dd)
>> nested_dd['a']['b']['c']['d'] = 'hello' >>> NestedDD = lambda: collections.defaultdict(NestedDD)
>>> nested_dd = NestedDD()
>>> nested_dd['a']['b']['c']['d'] = 'hello'
does the proper thing. >>> nested_dd['d']
'hello' from collections import defaultdict
defaultobj = lambda: type('defaultobj', (defaultdict,), {
'__getattr__': lambda self, x: self.__getitem__(x),
'__setattr__': lambda self, x, v: self.__setitem__(x, v)
})(defaultobj)
names = defaultobj()
names.mammalia.primates.homo['H. Sapiens'] = 'Human being'
print(names)
The same but also allows dot notation.