Python trie with defaultdict trick
from collections import defaultdict\n    \n    def _trie():\n        return defaultdict(_trie)\n    \n    TERMINAL = None\n    \n    class WordDictionary(object
    from collections import defaultdict\n    \n    def _trie():\n        return defaultdict(_trie)\n    \n    TERMINAL = None\n    \n    class WordDictionary(object):\n        def __init__(self):\n            self.trie = _trie()\n    \n        def addWord(self, word):\n            trie = self.trie\n            for letter in word:\n                trie = trie[letter]\n            trie[TERMINAL]\n    \n        def search(self, word, trie=None):\n            if trie is None:\n                trie = self.trie\n            for i, letter in enumerate(word):\n                if letter == '.':\n                    return any(self.search(word[i+1:], t) for t in trie.itervalues())\n                if letter in trie:\n                    trie = trie[letter]\n                else:\n                    return False\n            return TERMINAL in trie\n\nVery similar with the other trie-based solution but uses a less known `defaultdict` trick to make tries easier to build.
[]