Can someone help me understand tries in python? I was given this question but I am absolutely lost | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone help me understand tries in python? I was given this question but I am absolutely lost

Write the class method Trie.add, that consumes a Str and mutates the Trie so it also stores the new value. It returns None. For example, adding the word 'yo' to an empty Trie will cause it to look like: Trie ({ 'y': Trie ({ 'o': Trie ({ ' ': None }) }) }) If you further add 'ya', it will look like: Trie ({ 'y': Trie ({ 'o': Trie ({ ' ': None }) , 'a': Trie ({ ' ': None }) }) }) Let sample be an empty Trie. Add the words ['a', 'an', 'and', 'was', 'wax', 'way', 'win'] in order. Then sample will have the value: Trie ({ 'a': Trie ({ ' ': None , 'n': Trie ({ ' ': None , 'd': Trie ({ ' ': None }) }) }) , 'w': Trie ({ 'a': Trie ({ 's': Trie ({ ' ': None }) , 'x': Trie ({ ' ': None }) , 'y': Trie ({ ' ': None }) }) , 'i': Trie ({ 'n': Trie ({ ' ': None }) }) }) })

1st Apr 2020, 9:58 PM
Abhi Bhargo
Abhi Bhargo - avatar
1 Answer
+ 1
You need indentions and if-else statements. Just a clue.
3rd Apr 2020, 12:34 AM
James Clark I. Vinarao
James Clark I. Vinarao - avatar