Staging
v0.5.1
https://github.com/python/cpython
Revision 7e691de9483ac2565217ef547dd6fc135ea627ce authored by Guido van Rossum on 09 May 1997, 02:22:59 UTC, committed by Guido van Rossum on 09 May 1997, 02:22:59 UTC
Document how to get exit status of a popen() command.
1 parent e4f347e
Raw File
Tip revision: 7e691de9483ac2565217ef547dd6fc135ea627ce authored by Guido van Rossum on 09 May 1997, 02:22:59 UTC
Document return value of wait[pid]() more carefully.
Tip revision: 7e691de
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