Staging
v0.5.1
https://github.com/python/cpython
Revision f1fcc81a01c344ecad52156adb4a327bc2a005ea authored by Tim Peters on 25 September 2000, 21:55:28 UTC, committed by Tim Peters on 25 September 2000, 21:55:28 UTC
Note that somebody still needs to change the interpreter to say "2.0b2";
I'm assuming that's a normal part of somebody's Unix release checklist.
1 parent 9e7dd4c
Raw File
Tip revision: f1fcc81a01c344ecad52156adb4a327bc2a005ea authored by Tim Peters on 25 September 2000, 21:55:28 UTC
Bump Windows "build number" to 6.
Tip revision: f1fcc81
bisect.py
"""Bisection algorithms."""


def insort(a, x, lo=0, hi=None):
    """Insert item x in list a, and keep it sorted assuming a is sorted."""
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)/2
        if x < a[mid]: hi = mid
        else: lo = mid+1
    a.insert(lo, x)


def bisect(a, x, lo=0, hi=None):
    """Find the index where to insert item x in list a, assuming a is sorted."""
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)/2
        if x < a[mid]: hi = mid
        else: lo = mid+1
    return lo
back to top