Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
I was reading the gist @https://gist.github.com/2012250
I found the autovivification functionality of it pretty cool. If only I could have a parent reference...
Obviously this was not going to be a one-line tree. But that wasn't the goal
A simple variant:
from collections import defaultdict