def tree():
    return defaultdict(tree)
nested = defaultdict(tree)
words = ['Apple', 'Ape', 'Bark', 'Barn']
for word in words:
    node = nested
for char in word:
    node = node[char.upper()]
nested

def print_nested(d, indent=0):
    for k, v in d.items():
        print('{}{!r}:'.format(indent * '  ', k))
print_nested(v, indent + 1)
print_nested(nested)
Create a nested dictionary for a word python