Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Created June 27, 2014 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyrexus/2649d92130d0b82ecaa6 to your computer and use it in GitHub Desktop.
Save joyrexus/2649d92130d0b82ecaa6 to your computer and use it in GitHub Desktop.
Autovivifying dicts

Use autodict() to create an autovivify dict:

from collections import defaultdict as dd

def autodict():
    return dd(autodict)

d = autodict()
d['an']['arbitrarily']['deep']['dictionary'] = "yes!"
assert d['an']['arbitrarily']['deep']['dictionary'] is "yes!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment