Complete the code to insert a word into the Trie.
def insert_word(root, word): node = root for char in word: if char not in node.children: node.children[[1]] = TrieNode() node = node.children[char] node.is_end = True
We use the current character char as the key to check and add in the children dictionary.
Complete the code to check if a prefix exists in the Trie.
def starts_with(root, prefix): node = root for char in prefix: if [1] not in node.children: return False node = node.children[char] return True
We check if the current character char is in the children dictionary.
Fix the error in the code to search a word in the Trie.
def search_word(root, word): node = root for char in word: if char not in node.children: return False node = node.children[[1]] return node.is_end
We must use the current character char to move to the next node in children.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
{word: [1] for word in words if len(word) [2] 3}The dictionary maps each word to its length, and filters words with length greater than 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 2.
{ [1]: [2] for word in words if len(word) [3] 2 }The dictionary keys are uppercase words, values are their lengths, filtered by length greater than 2.
