>>> trie = Trie() >>> for word in words: ... trie.insert_word(word) ... >>> matches = autocomplete_using_trie("de") >>> "detergent " in matches True >>> "dog " in matches False
(string: str)
| 39 | |
| 40 | |
| 41 | def autocomplete_using_trie(string: str) -> tuple: |
| 42 | """ |
| 43 | >>> trie = Trie() |
| 44 | >>> for word in words: |
| 45 | ... trie.insert_word(word) |
| 46 | ... |
| 47 | >>> matches = autocomplete_using_trie("de") |
| 48 | >>> "detergent " in matches |
| 49 | True |
| 50 | >>> "dog " in matches |
| 51 | False |
| 52 | """ |
| 53 | suffixes = trie.find_word(string) |
| 54 | return tuple(string + word for word in suffixes) |
| 55 | |
| 56 | |
| 57 | def main() -> None: |