python 3.x – How to create an autocomplete method that looks for an existing trie in pythonn

I'm new to Python, I found different codes that implement trie, like this, for example:

from collections import default
TrieNode class:
def __init __ (self):
self.children = defaultdict (TrieNode)
self.isEnd = False
def insert (auto, word):
node = yo
for w in word:
node = node.children[w]
        node.isEnd = True
def search (auto, word):
node = yo
for w in word:
if w in node.children:
node = node.children[w]
            plus:
he came back []
        # prefix coincidence
# traverse currnt node to all leaf nodes
result = []
        self.traverse (node, list (word), result)
he came back [''.join(r) for r in result]

    Def crossing (auto, root, prefix, result):
yes root.isEnd:
result.append (prefix[:])
for c, n in root.children.items ():
prefix.append (c)
self.traverse (n, prefix, result)
prefix.pop (-1)
yes __name__ == "__main__":
words = ['a', 'apple', 'angle', 'angel', 'bat', 'bats']
    root = TrieNode ()
for w in words:
root.insert (w)

print (root.search (& # 39; an & # 39;)) # ['angle', 'angel']
    print (root.search (& # 39; ap & # 39;)) # ['apple']

What I am trying to achieve is to create a method that looks for an existing test and produces a list of suggestions, instead of creating a test every time, for example, the existing word for words = [‘a’, ‘apple’, ‘angle’, ‘angel’, ‘bat’, ‘bats’] is:
{& # 39; a & # 39 ;: {& # 39;& # 39;: & # 39;& # 39;, & # 39; p & # 39 ;: {& # 39; p & # 39 ;: {& # 39; l & # 39 ;: {& # 39; e & # 39 ;: {& # 39;& # 39;: & # 39;& # 39;}}}}}, & # 39; n & # 39 ;: {& # 39; g & # 39 ;: {& # 39; l & # 39 ;: {& # 39; e & # 39 ;: {& # 39;& # 39;: & # 39;& # 39;}}, & # 39; e & # 39 ;: {& # 39; l & # 39 ;: {& # 39;& # 39;: & # 39;& # 39 ;:}}}}}, & # 39; bat & # 39 ;: {& # 39;& # 39;: & # 39;& # 39;, & # 39; s & # 39 ;: {& # 39;& # 39;: & # 39;& # 39;}}}}}

What I was able to obtain through another code:

_end = & # 39; * & # 39;

# take a list of words
def make_trie (* words):
# create our root dict ()
trie = dict ()

for word in words:
# create a temporary dict based on our root
#dict object
temp_dict = trie

by letter in word:
# Update our temporary opinion and add our current
# letter and a sub-dictionary
temp_dict = temp_dict.setdefault (letter, {})

# If our word has ended, add {& # 39; * & # 39 ;: & # 39; * & # 39;}
# This tells us that our word is finished.
temp_dict[_end] = _end
back trie
def find_word (trie, word):
sub_trie = trie
mylist = []
    by letter in word:
if letter in sub_trie:
sub_trie = sub_trie[letter]
            mylist.append (letter)

plus:
false return
plus:
if _end in sub_trie:
return true
plus:
false return

# Test our creation trie
trie = make_trie (& # 39 ;, & # 39; apple & # 39 ;, & # 39; angle & # 39 ;, & # 39; angel & # 39 ;, & # 39; bat & # 39 ;, & # 39; bats & # 39;)
# print our new trie
print (trie)
find = find_word (trie, "apple")
print (find)

Please help..