diff options
Diffstat (limited to 'Lib/bisect.py')
| -rw-r--r-- | Lib/bisect.py | 36 | 
1 files changed, 17 insertions, 19 deletions
diff --git a/Lib/bisect.py b/Lib/bisect.py index 5fbc4ef..47ef509 100644 --- a/Lib/bisect.py +++ b/Lib/bisect.py @@ -1,25 +1,23 @@ -# Bisection algorithms +"""Bisection algorithms.""" -# Insert item x in list a, and keep it sorted assuming a is sorted -  def insort(a, x, lo=0, hi=None): -	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) - +    """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) -# Find the index where to insert item x in list a, assuming a is sorted  def bisect(a, x, lo=0, hi=None): -	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 +    """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  | 
