Skip to content

Instantly share code, notes, and snippets.

@rbarzic
Created May 23, 2018 07:13
Show Gist options
  • Save rbarzic/3363b5ce48f92e90aae545d850d6813d to your computer and use it in GitHub Desktop.
Save rbarzic/3363b5ce48f92e90aae545d850d6813d to your computer and use it in GitHub Desktop.
Autovification in Python using defaultdict
# From https://stackoverflow.com/questions/5369723/multi-level-defaultdict-with-variable-depth/8702435#8702435
from collections import defaultdict
nested_dict = lambda: defaultdict(nested_dict)
nest = nested_dict()
nest[0][1][2][3][4][5] = 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment