Python Trie Solution
The idea is the same as Stefan\'s elegant solution: https://leetcode.com/problems/add-and-search-word-data-structure-design/discuss/59576/Tree-solutions-18-20-l
The idea is the same as Stefan\'s elegant solution: https://leetcode.com/problems/add-and-search-word-data-structure-design/discuss/59576/Tree-solutions-18-20-lines  But the differences are: 1. My code is using a class for Trie; 2. It has early return if the word is found; 3. It is not using pythonic "list comprehension", so in the end, it\'s slower than Stefan\'s code. But for reference, here is the code:\n```\nclass TrieNode:\n    def __init__(self):\n        self.children = {}\n        self.isWord = False\n\nclass WordDictionary:\n\n    def __init__(self):\n        """\n        Initialize your data structure here.\n        """\n        self.root = TrieNode()\n\n    def addWord(self, word):\n        """\n        Adds a word into the data structure.\n        :type word: str\n        :rtype: void\n        """\n        cur = self.root\n        for c in word:\n            if c not in cur.children:\n                cur.children[c] = TrieNode()\n            cur = cur.children[c]\n        cur.isWord = True\n\n    def search(self, word):\n        """\n        Returns if the word is in the data structure. A word could contain the dot character \'.\' to represent any one letter.\n        :type word: str\n        :rtype: bool\n        """\n        cur = [self.root]\n        for i, c in enumerate(word):\n            newcur = []\n            for node in cur:\n                for ck, cv in node.children.items():\n                    if c == \'.\' or c == ck:\n                        if i == len(word) - 1 and cv.isWord:\n                            return True\n                        newcur.append(cv)\n            cur = newcur\n        return False\n```
[]