December 2023
Intermediate to advanced
504 pages
11h 43m
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 collect_all_words, collects a list of all the trie’s words starting from a particular node:
| | def collect_all_words(self, words, node=None, word=""): |
| | current_node ... |
Read now
Unlock full access