classTrieNode(object):def__init__(self):""" Initialize your data structure here. """self.isWord=False# if this node has a wordself.children=dict()# all children nodesclassTrie(object):def__init__(self):self.root=TrieNode()definsert(self,word):""" Inserts a word into the trie. :type word: str :rtype: void """node=self.rootforletterinword:child=node.children.get(letter)ifchild==None:child=TrieNode()node.children[letter]=childnode=childnode.isWord=Truedefsearch(self,word):""" Returns if the word is in the trie. :type word: str :rtype: bool """node=self.rootforletterinword:child=node.children.get(letter)ifchild==None:returnFalsenode=childifnode.isWord==True:returnTrueelse:returnFalsedefstartsWith(self,prefix):""" Returns if there is any word in the trie that starts with the given prefix. :type prefix: str :rtype: bool """node=self.rootforletterinprefix:child=node.children.get(letter)ifchild==None:returnFalsenode=childreturnTrue# Your Trie object will be instantiated and called as such:# trie = Trie()# trie.insert("somestring")# trie.search("key")