Skip to content

Instantly share code, notes, and snippets.

@wkettler
Last active August 29, 2015 14:11
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 wkettler/567510c391b99d5b498c to your computer and use it in GitHub Desktop.
Save wkettler/567510c391b99d5b498c to your computer and use it in GitHub Desktop.
Autovivification removes need for horrendous nested calls to {}.setdefault() when working with trees in python. my_tree = tree() my_tree['tra']['la']['la']
from collections import defaultdict
def tree():
return defaultdict(tree)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment