Defaultdict not returning default values

d1 = defaultdict(lambda : defaultdict(lambda : defaultdict (lambda : 0)))
d1['first']['second'] = 2 #Assigning some value
d1['first']['third']   #Expecting to return the default value, which is 0, but ...
defaultdict(<function <lambda>.<locals>.<lambda>.<locals>.<lambda> at 0x7ff5765421e0>, {})

Why is this not returning 0 ?


Because there are three levels of defaultdicts until you reach the value 0, so you need to do:

>>> d1['first']['second']['third']
0