Skip to content

Commit f574e49

Browse files
committed
Update word-pattern.py
1 parent a032f74 commit f574e49

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Python/word-pattern.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
# 3. Each word in str is separated by a single space.
1616
# 4. Each letter in pattern must map to a word with length that is at least 1.
1717

18-
# Lengthy code but saving more spaces
18+
from itertools import izip
19+
1920
class Solution(object):
2021
# Word generates at a time without saving all the words.
2122
class WordGenerator(object):
@@ -42,8 +43,7 @@ def wordPattern(self, pattern, str):
4243
return False
4344

4445
w2p, p2w = {}, {}
45-
for i, w in enumerate(self.WordGenerator(str)):
46-
p = pattern[i]
46+
for p, w in izip(pattern, self.WordGenerator(str)):
4747
if w not in w2p and p not in p2w:
4848
# Build mapping.
4949
w2p[w] = p

0 commit comments

Comments
 (0)