August 2020
Intermediate to advanced
508 pages
11h 53m
English
We’re just about ready to build a real autocomplete feature. To make this a tad easier, let’s first build a slightly simpler function that we’ll use to help us with this feature.
The next method we’re going to add to our Trie class is a method that returns an array of all the words in the trie. Now, it’s rare that we’d actually want to list the entire dictionary. However, we’re going to allow this method to accept any node of the trie as an argument so that it can list all the words that start from that node.
The following method, called collectAllWords, collects a list of all the trie’s words starting from a particular node:
| | def collectAllWords(self, node=None, word="", words=[]): |
| | # This ... |
Read now
Unlock full access