Skip to content

Commit 9622465

Browse files
authored
Merge pull request rougier#67 from bruno314/off-by-one
Off by one error
2 parents 5664322 + a8b8c1f commit 9622465

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

02-introduction.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ and you don't need to read this book).
156156
.. code:: python
157157
158158
def function_1(seq, sub):
159-
return [i for i in range(len(seq) - len(sub)) if seq[i:i+len(sub)] == sub]
159+
return [i for i in range(len(seq) - len(sub) +1) if seq[i:i+len(sub)] == sub]
160160
161161
def function_2(seq, sub):
162162
target = np.dot(sub, sub)

code/random_walk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def random_walk_fastest(n=1000):
4747
# -----------------------------------------------------------------------------
4848
# Readable but slow
4949
def find_crossing_1(seq, sub):
50-
return [i for i in range(len(seq) - len(sub)) if seq[i:i+len(sub)] == sub]
50+
return [i for i in range(len(seq) - len(sub) +1) if seq[i:i+len(sub)] == sub]
5151

5252
# Fast but hardly readable
5353
def find_crossing_2(seq, sub):

0 commit comments

Comments
 (0)