def wordPattern(self, pattern, str):
        """
        :type pattern: str
        :type str: str
        :rtype: bool
        """
        words = str.split()  # Space: O(n)
        if len(pattern) != len(words):
            return False

        w2p, p2w = {}, {}
        for p, w in izip(pattern, words):
            if w not in w2p and p2w not in p:
                # Build mapping. Space: O(c)
                w2p[w] = p
                p2w[p] = w 
            elif w not in w2p or w2p[w] != p:
                # Contradict mapping.
                return False
        return True
dataset/ETHPy150Open kamyu104/LeetCode/Python/word-pattern.py/Solution2.wordPattern/swapped operands of `not in`