Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/python3....
File: bisect.py
"""Bisection algorithms."""
[0] Fix | Delete
[1] Fix | Delete
def insort_right(a, x, lo=0, hi=None):
[2] Fix | Delete
"""Insert item x in list a, and keep it sorted assuming a is sorted.
[3] Fix | Delete
[4] Fix | Delete
If x is already in a, insert it to the right of the rightmost x.
[5] Fix | Delete
[6] Fix | Delete
Optional args lo (default 0) and hi (default len(a)) bound the
[7] Fix | Delete
slice of a to be searched.
[8] Fix | Delete
"""
[9] Fix | Delete
[10] Fix | Delete
lo = bisect_right(a, x, lo, hi)
[11] Fix | Delete
a.insert(lo, x)
[12] Fix | Delete
[13] Fix | Delete
def bisect_right(a, x, lo=0, hi=None):
[14] Fix | Delete
"""Return the index where to insert item x in list a, assuming a is sorted.
[15] Fix | Delete
[16] Fix | Delete
The return value i is such that all e in a[:i] have e <= x, and all e in
[17] Fix | Delete
a[i:] have e > x. So if x already appears in the list, a.insert(x) will
[18] Fix | Delete
insert just after the rightmost x already there.
[19] Fix | Delete
[20] Fix | Delete
Optional args lo (default 0) and hi (default len(a)) bound the
[21] Fix | Delete
slice of a to be searched.
[22] Fix | Delete
"""
[23] Fix | Delete
[24] Fix | Delete
if lo < 0:
[25] Fix | Delete
raise ValueError('lo must be non-negative')
[26] Fix | Delete
if hi is None:
[27] Fix | Delete
hi = len(a)
[28] Fix | Delete
while lo < hi:
[29] Fix | Delete
mid = (lo+hi)//2
[30] Fix | Delete
# Use __lt__ to match the logic in list.sort() and in heapq
[31] Fix | Delete
if x < a[mid]: hi = mid
[32] Fix | Delete
else: lo = mid+1
[33] Fix | Delete
return lo
[34] Fix | Delete
[35] Fix | Delete
def insort_left(a, x, lo=0, hi=None):
[36] Fix | Delete
"""Insert item x in list a, and keep it sorted assuming a is sorted.
[37] Fix | Delete
[38] Fix | Delete
If x is already in a, insert it to the left of the leftmost x.
[39] Fix | Delete
[40] Fix | Delete
Optional args lo (default 0) and hi (default len(a)) bound the
[41] Fix | Delete
slice of a to be searched.
[42] Fix | Delete
"""
[43] Fix | Delete
[44] Fix | Delete
lo = bisect_left(a, x, lo, hi)
[45] Fix | Delete
a.insert(lo, x)
[46] Fix | Delete
[47] Fix | Delete
[48] Fix | Delete
def bisect_left(a, x, lo=0, hi=None):
[49] Fix | Delete
"""Return the index where to insert item x in list a, assuming a is sorted.
[50] Fix | Delete
[51] Fix | Delete
The return value i is such that all e in a[:i] have e < x, and all e in
[52] Fix | Delete
a[i:] have e >= x. So if x already appears in the list, a.insert(x) will
[53] Fix | Delete
insert just before the leftmost x already there.
[54] Fix | Delete
[55] Fix | Delete
Optional args lo (default 0) and hi (default len(a)) bound the
[56] Fix | Delete
slice of a to be searched.
[57] Fix | Delete
"""
[58] Fix | Delete
[59] Fix | Delete
if lo < 0:
[60] Fix | Delete
raise ValueError('lo must be non-negative')
[61] Fix | Delete
if hi is None:
[62] Fix | Delete
hi = len(a)
[63] Fix | Delete
while lo < hi:
[64] Fix | Delete
mid = (lo+hi)//2
[65] Fix | Delete
# Use __lt__ to match the logic in list.sort() and in heapq
[66] Fix | Delete
if a[mid] < x: lo = mid+1
[67] Fix | Delete
else: hi = mid
[68] Fix | Delete
return lo
[69] Fix | Delete
[70] Fix | Delete
# Overwrite above definitions with a fast C implementation
[71] Fix | Delete
try:
[72] Fix | Delete
from _bisect import *
[73] Fix | Delete
except ImportError:
[74] Fix | Delete
pass
[75] Fix | Delete
[76] Fix | Delete
# Create aliases
[77] Fix | Delete
bisect = bisect_right
[78] Fix | Delete
insort = insort_right
[79] Fix | Delete
[80] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function