>>> def a(): b = lambda: defaultdict(b); return b() >>> x = a(); x[1][2][3] = 'Infinity!'; print dumps(x) {"1": {"2": {"3": "infinity!"}}}Defining B in A prevents renames of A from breaking dictionaries made with B.
(prior art)
>>> def a(): b = lambda: defaultdict(b); return b() >>> x = a(); x[1][2][3] = 'Infinity!'; print dumps(x) {"1": {"2": {"3": "infinity!"}}}Defining B in A prevents renames of A from breaking dictionaries made with B.