Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72bfc9d

Browse files
committed
Fixed Wordlist bugs: hi must be int, and list may be empty.
1 parent d6cdfae commit 72bfc9d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

search.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,14 +593,15 @@ def lookup(self, prefix, lo=0, hi=None):
593593
words[i].startswith(prefix), or is None; the second is
594594
True iff prefix itself is in the Wordlist."""
595595
words = self.words
596+
if hi is None: hi = len(words)
596597
i = bisect.bisect_left(words, prefix, lo, hi)
597598
if i < len(words) and words[i].startswith(prefix):
598599
return i, (words[i] == prefix)
599600
else:
600601
return None, False
601602

602603
def __contains__(self, word):
603-
return self.words[bisect.bisect_left(self.words, word)] == word
604+
return self.lookup(word)[1]
604605

605606
def __len__(self):
606607
return len(self.words)

0 commit comments

Comments
 (0)