I'm Brett Slatkin and this is where I write about programming and related topics. Check out my favorite posts if you're new to this site. You can also 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-2019 Brett Slatkin