I have this trie dictionary:
JavaScript
x
6
1
{'s': {'h': {'o': {'w': {'value': 'a programm'},
2
'o': {'t': {'value':'a bullet'}},
3
'e': {'value': 's.th to wear'}},
4
'a': {'m': {'e': {'value': 'a feeling'}}},
5
'i': {'t': {'value': 'deficate'}}}}}
6
I want to define a function that searches through this trie dict and finds its values. how to do it ?
Advertisement
Answer
here is how I do it:
JavaScript
1
14
14
1
def finder(dict_trie,word):
2
if word:
3
first,rest = word[0],word[1:]
4
finder(dict_trie[first],rest)
5
else:
6
print(dict_trie["value"])
7
8
9
10
finder(dict_trie,"shit")
11
12
13
result = deficate
14