>>> def tree(func=None, level=-1):
... if not func:
... func = tree
... if not level:
... return func()
... return defaultdict(lambda : tree(func, level-1))
...
>>> f = tree()
>>> f
defaultdict(<function <lambda> at 0x2b00e978>, {})
>>> f[3]
defaultdict(<function <lambda> at 0x2b00eb28>, {})
>>> f[1][2][3][4]
defaultdict(<function <lambda> at 0x2b00ec48>, {})
>>> f = tree(float, 3)
>>> f[1]
defaultdict(<function <lambda> at 0x2b00eb28>, {})
>>> f[1][2]
defaultdict(<function <lambda> at 0x2b00ec00>, {})
>>> f[1][2][3]
0.0