Skip to content

Commit dfe327a

Browse files
committed
Update word-pattern.py
1 parent b88a8d2 commit dfe327a

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

Python/word-pattern.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def wordPattern(self, pattern, str):
2828
return False
2929

3030
w2p, p2w = {}, {}
31-
for p, w in izip(pattern, self.WordGenerator(str)):
31+
for p, w in izip(pattern, self.wordGenerator(str)):
3232
if w not in w2p and p not in p2w:
3333
# Build mapping.
3434
w2p[w] = p
@@ -46,19 +46,15 @@ def wordCount(self, str):
4646
return cnt
4747

4848
# Word generates at a time without saving all the words.
49-
class WordGenerator(object):
50-
def __init__(self, str):
51-
self.str = str
52-
53-
def __iter__(self):
54-
w = ""
55-
for c in self.str:
56-
if c == ' ':
57-
yield w
58-
w = ""
59-
else:
60-
w += c
61-
yield w
49+
def wordGenerator(self, str):
50+
w = ""
51+
for c in str:
52+
if c == ' ':
53+
yield w
54+
w = ""
55+
else:
56+
w += c
57+
yield w
6258

6359

6460
# Time: O(n)

0 commit comments

Comments
 (0)