Using regular expressions (AC, 315 ms)
With dots representing any letter, this problem is basically begging for a regular expression solution :-)\n\n    class WordDictionary:\n    \n        def init(
With dots representing any letter, this problem is basically *begging* for a regular expression solution :-)\n\n    class WordDictionary:\n    \n        def __init__(self):\n            self.words = \'#\'\n        \n        def addWord(self, word):\n            self.words += word + \'#\'\n    \n        def search(self, word):\n            return bool(re.search(\'#\' + word + \'#\', self.words))\n\nAnother way (added Jan 2020):\n```\nclass WordDictionary:\n\n    def __init__(self):\n        self.words = collections.defaultdict(set)\n    \n    def addWord(self, word):\n        self.words[len(word)].add(word)\n\n    def search(self, word):\n        return any(map(re.compile(word).match,\n                       self.words[len(word)]))\n```
['Python']