From 4e16098ce74c645cf1d69566b6f8bc96031554b7 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 2 Sep 1992 20:43:20 +0000 Subject: Added a _v21 def to FL.py and added two new input field types Added runcall(func, *args) interfaces to profile.py, bdb.py, pdb.py, wdb.py Added new module bisect.py and used it in sched.py. Mostly cosmetic changes to profile.py (changed output format). --- Lib/bisect.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Lib/bisect.py (limited to 'Lib/bisect.py') diff --git a/Lib/bisect.py b/Lib/bisect.py new file mode 100644 index 0000000000..688666a411 --- /dev/null +++ b/Lib/bisect.py @@ -0,0 +1,23 @@ +# Bisection algorithms + + +# Insert item x in list a, and keep it sorted assuming a is sorted + +def insort(a, x): + lo, hi = 0, len(a) + while lo < hi: + mid = (lo+hi)/2 + if x < a[mid]: hi = mid + else: lo = mid+1 + a.insert(lo, 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) + while lo < hi: + mid = (lo+hi)/2 + if x < a[mid]: hi = mid + else: lo = mid+1 + return lo -- cgit v1.2.1