:type pattern: str :type str: str :rtype: bool
(self, pattern, string)
| 34 | """ |
| 35 | class Solution(object): |
| 36 | def wordPattern(self, pattern, string): |
| 37 | """ |
| 38 | :type pattern: str |
| 39 | :type str: str |
| 40 | :rtype: bool |
| 41 | """ |
| 42 | pattern = list(pattern) |
| 43 | string = string.split(' ') |
| 44 | if len(pattern) != len(string): |
| 45 | return False |
| 46 | temp = len(set(zip(pattern, string))) |
| 47 | return temp == len(set(pattern)) and temp == len(set(string)) |