Mercurial > cpython-lru_cache-weakref
view Lib/bisect.py @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 903071377d29 |
| children | fb9b0d246ef3 |
line wrap: on
line source
# 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
