[Python-checkins] remove duplicate code in biscet (GH-1270)

Inada Naoki webhook-mailer at python.org
Mon Apr 8 04:01:21 EDT 2019


https://github.com/python/cpython/commit/96be3400a97946b0b3d032dd8c3c0561786796f1
commit: 96be3400a97946b0b3d032dd8c3c0561786796f1
branch: master
author: Chillar Anand <chillar at avilpage.com>
committer: Inada Naoki <songofacandy at gmail.com>
date: 2019-04-08T17:01:09+09:00
summary:

remove duplicate code in biscet (GH-1270)

files:
M Lib/bisect.py

diff --git a/Lib/bisect.py b/Lib/bisect.py
index 7732c639e386..9786fc9d87c5 100644
--- a/Lib/bisect.py
+++ b/Lib/bisect.py
@@ -9,14 +9,7 @@ def insort_right(a, x, lo=0, hi=None):
     slice of a to be searched.
     """
 
-    if lo < 0:
-        raise ValueError('lo must be non-negative')
-    if hi is None:
-        hi = len(a)
-    while lo < hi:
-        mid = (lo+hi)//2
-        if x < a[mid]: hi = mid
-        else: lo = mid+1
+    lo = bisect_right(a, x, lo, hi)
     a.insert(lo, x)
 
 def bisect_right(a, x, lo=0, hi=None):
@@ -49,14 +42,7 @@ def insort_left(a, x, lo=0, hi=None):
     slice of a to be searched.
     """
 
-    if lo < 0:
-        raise ValueError('lo must be non-negative')
-    if hi is None:
-        hi = len(a)
-    while lo < hi:
-        mid = (lo+hi)//2
-        if a[mid] < x: lo = mid+1
-        else: hi = mid
+    lo = bisect_left(a, x, lo, hi)
     a.insert(lo, x)
 
 



More information about the Python-checkins mailing list