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!"