class TrieNode: def __init__(self): self.nodes = dict() # build dictionary self.is_leaf = False def insert(self, word: str): curr = self for char in word: if char not incurr.nodes: curr.nodes[char] = TrieNode() curr = curr.nodes[char] curr.is_leaf = True
This is a class of a dictionary tree. Can you please tell me the meaning of the code in this part of the insert function? For example, I don't understand why this line of code is curr=self. There is also curr.nodes[char]=TrieNode() curr=curr.nodes[char] I don't quite understand these lines