]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add optional arguments lo and hi to insort() and bisect(), to support
authorGuido van Rossum <guido@python.org>
Tue, 7 Oct 1997 14:45:49 +0000 (14:45 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 7 Oct 1997 14:45:49 +0000 (14:45 +0000)
using arrays containing leading or trailing garbage.

Lib/bisect.py

index 688666a411651e287512afda514cb3aa402a72d0..4d92bc8e8aad661d74089cf0029be3e9477c881d 100644 (file)
@@ -3,8 +3,9 @@
 
 # Insert item x in list a, and keep it sorted assuming a is sorted
 
-def insort(a, x):
-        lo, hi = 0, len(a)
+def insort(a, x, lo=0, hi=None):
+       if hi is None:
+               hi = len(a)
         while lo < hi:
                mid = (lo+hi)/2
                if x < a[mid]: hi = mid
@@ -14,8 +15,9 @@ def insort(a, x):
 
 # Find the index where to insert item x in list a, assuming a is sorted
 
-def bisect(a, x):
-        lo, hi = 0, len(a)
+def bisect(a, x, lo=0, hi=None):
+       if hi is None:
+               hi = len(a)
         while lo < hi:
                mid = (lo+hi)/2
                if x < a[mid]: hi = mid