I'm Brett Slatkin and this is where I write about programming and related topics. You can contact me here or view my projects.

26 January 2013

Behold! The infinite dict.
>>> 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)
© 2009-2024 Brett Slatkin