Compute the common substring of the prefix of the node and a word Args: word (str): word to compare Returns: (str, str, str): common substring, remaining prefix, remaining word >>> RadixNode("myprefix").match("mystring") ('my', 'prefix', 'st
(self, word: str)
| 16 | self.prefix = prefix |
| 17 | |
| 18 | def match(self, word: str) -> tuple[str, str, str]: |
| 19 | """Compute the common substring of the prefix of the node and a word |
| 20 | |
| 21 | Args: |
| 22 | word (str): word to compare |
| 23 | |
| 24 | Returns: |
| 25 | (str, str, str): common substring, remaining prefix, remaining word |
| 26 | |
| 27 | >>> RadixNode("myprefix").match("mystring") |
| 28 | ('my', 'prefix', 'string') |
| 29 | """ |
| 30 | x = 0 |
| 31 | for q, w in zip(self.prefix, word): |
| 32 | if q != w: |
| 33 | break |
| 34 | |
| 35 | x += 1 |
| 36 | |
| 37 | return self.prefix[:x], self.prefix[x:], word[x:] |
| 38 | |
| 39 | def insert_many(self, words: list[str]) -> None: |
| 40 | """Insert many words in the tree |