MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / match

Method match

data_structures/trie/radix_tree.py:18–37  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 3

insertMethod · 0.80
findMethod · 0.80
deleteMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected