Last active
August 29, 2015 14:11
-
-
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']
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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