experimental.bisect
Functions for searching, splitting, and inserting into a sorted list
Copied from https://github.com/python/cpython/blob/3.12/Lib/bisect.py with some modifications noted in-line with # EDIT
- experimental.bisect.bisect(a, x, lo=0, hi=None, *, key=None)
Return the index where to insert item x in list a, assuming a is sorted.
The return value i is such that all e in a[:i] have e <= x, and all e in a[i:] have e > x. So if x already appears in the list, a.insert(i, x) will insert just after the rightmost x already there.
- Parameters
a – The sorted array we’re inserting into
x – The value we’re inserting into the array
lo – the lower bound of the array slice to consider
hi – the upper bound of the array slice to consider
key – an optional key function for sorting the data
- experimental.bisect.bisect_left(a, x, lo=0, hi=None, *, key=None)
Return the index where to insert item x in list a, assuming a is sorted.
The return value i is such that all e in a[:i] have e < x, and all e in a[i:] have e >= x. So if x already appears in the list, a.insert(i, x) will insert just before the leftmost x already there.
- Parameters
a – The sorted array we’re inserting into
x – The value we’re inserting into the array
lo – the lower bound of the array slice to consider
hi – the upper bound of the array slice to consider
key – an optional key function for sorting the data
- experimental.bisect.bisect_right(a, x, lo=0, hi=None, *, key=None)
Return the index where to insert item x in list a, assuming a is sorted.
The return value i is such that all e in a[:i] have e <= x, and all e in a[i:] have e > x. So if x already appears in the list, a.insert(i, x) will insert just after the rightmost x already there.
- Parameters
a – The sorted array we’re inserting into
x – The value we’re inserting into the array
lo – the lower bound of the array slice to consider
hi – the upper bound of the array slice to consider
key – an optional key function for sorting the data
- experimental.bisect.insort(a, x, lo=0, hi=None, *, key=None)
Insert item x in list a, and keep it sorted assuming a is sorted.
If x is already in a, insert it to the right of the rightmost x.
- Parameters
a – The array we’re inserting into
x – The value we’re inserting into the array
lo – the lower bound of the array slice to consider
hi – the upper bound of the array slice to consider
key – an optional key function for sorting the data
- experimental.bisect.insort_left(a, x, lo=0, hi=None, *, key=None)
Insert item x in list a, and keep it sorted assuming a is sorted.
If x is already in a, insert it to the left of the leftmost x.
- Parameters
a – The sorted array we’re inserting into
x – The value we’re inserting into the array
lo – the lower bound of the array slice to consider
hi – the upper bound of the array slice to consider
key – an optional key function for sorting the data
- experimental.bisect.insort_right(a, x, lo=0, hi=None, *, key=None)
Insert item x in list a, and keep it sorted assuming a is sorted.
If x is already in a, insert it to the right of the rightmost x.
- Parameters
a – The array we’re inserting into
x – The value we’re inserting into the array
lo – the lower bound of the array slice to consider
hi – the upper bound of the array slice to consider
key – an optional key function for sorting the data