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

Skip to content

Commit d5484fb

Browse files
committed
Add optional arguments lo and hi to insort() and bisect(), to support
using arrays containing leading or trailing garbage.
1 parent eec6ef1 commit d5484fb

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

Lib/bisect.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
# Insert item x in list a, and keep it sorted assuming a is sorted
55

6-
def insort(a, x):
7-
lo, hi = 0, len(a)
6+
def insort(a, x, lo=0, hi=None):
7+
if hi is None:
8+
hi = len(a)
89
while lo < hi:
910
mid = (lo+hi)/2
1011
if x < a[mid]: hi = mid
@@ -14,8 +15,9 @@ def insort(a, x):
1415

1516
# Find the index where to insert item x in list a, assuming a is sorted
1617

17-
def bisect(a, x):
18-
lo, hi = 0, len(a)
18+
def bisect(a, x, lo=0, hi=None):
19+
if hi is None:
20+
hi = len(a)
1921
while lo < hi:
2022
mid = (lo+hi)/2
2123
if x < a[mid]: hi = mid

0 commit comments

Comments
 (0)