Word Pattern - Leetcode 290 - Python