✅ [Python] 7 Lines || Inverted Index || Short and Easy to Understand
PLEASE UPVOTE if you like \uD83D\uDE01 If you have any question, feel free to ask. \n\n\nclass WordDictionary(object):\n\n    def __init__(self):\n        self.
**PLEASE UPVOTE if you like** \uD83D\uDE01 **If you have any question, feel free to ask.** \n\n```\nclass WordDictionary(object):\n\n    def __init__(self):\n        self.dict, self.len2word  = defaultdict(set), defaultdict(set)\n\n    def addWord(self, word):\n        # self.dict: key is combination of index and character, value is a word set whose i-th letter is c\n        for i, c in enumerate(word): self.dict[(i, c)].add(word)\n        # self.len2word: key is length of word, value is a word set whose length is equal to key\n        self.len2word[len(word)].add(word)\n\n    def search(self, word):\n        ans = copy.deepcopy(self.len2word[len(word)])\n        for i, c in enumerate(word):\n            if c != \'.\': ans &= self.dict[(i, c)]\n        return True if len(ans) else False\n```
['Python']