X Tutup
Skip to content

Commit 96be340

Browse files
ChillarAnandmethane
authored andcommitted
remove duplicate code in biscet (pythonGH-1270)
1 parent b7eec94 commit 96be340

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

Lib/bisect.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@ def insort_right(a, x, lo=0, hi=None):
99
slice of a to be searched.
1010
"""
1111

12-
if lo < 0:
13-
raise ValueError('lo must be non-negative')
14-
if hi is None:
15-
hi = len(a)
16-
while lo < hi:
17-
mid = (lo+hi)//2
18-
if x < a[mid]: hi = mid
19-
else: lo = mid+1
12+
lo = bisect_right(a, x, lo, hi)
2013
a.insert(lo, x)
2114

2215
def bisect_right(a, x, lo=0, hi=None):
@@ -49,14 +42,7 @@ def insort_left(a, x, lo=0, hi=None):
4942
slice of a to be searched.
5043
"""
5144

52-
if lo < 0:
53-
raise ValueError('lo must be non-negative')
54-
if hi is None:
55-
hi = len(a)
56-
while lo < hi:
57-
mid = (lo+hi)//2
58-
if a[mid] < x: lo = mid+1
59-
else: hi = mid
45+
lo = bisect_left(a, x, lo, hi)
6046
a.insert(lo, x)
6147

6248

0 commit comments

Comments
 (0)
X Tutup