Staging
v0.8.1
https://github.com/python/cpython
Revision 2281d35578450e7ee15c94b8667aa59bf406256c authored by Guido van Rossum on 26 June 1996, 19:47:37 UTC, committed by Guido van Rossum on 26 June 1996, 19:47:37 UTC
1 parent 2d38f91
Raw File
Tip revision: 2281d35578450e7ee15c94b8667aa59bf406256c authored by Guido van Rossum on 26 June 1996, 19:47:37 UTC
add nturl2path
Tip revision: 2281d35
bisect.py
# 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
back to top