mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Mass patch by Ka-Ping Yee:
1. Comments at the beginning of the module, before functions, and before classes have been turned into docstrings. 2. Tabs are normalized to four spaces. Also, removed the "remove" function from dircmp.py, which reimplements list.remove() (it must have been very old).
This commit is contained in:
parent
113e70efa2
commit
4acc25bd39
18 changed files with 2513 additions and 2515 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue