collections Table of Contents defaultdict defaultdict # A dict of indefinite depth elements def tree(): return defaultdict(tree) https://docs.python.org/3/library/collections.html#collections.defaultdict