from collections import defaultdict f = lambda: defaultdict(f) recursive_defaultdict = defauldict(f)