Bisection Functions
bisect.insort_right()
Insert x into a sorted mutable sequence after existing equal keys. The key function is applied to x for searching, but x itself is inserted. Search is logarithmic; list insertion is linear.
Formal Syntax & Structure
python syntaxpython
bisect.insort_right(a, x, lo=0, hi=None, *, key=None)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| a | sequence | Sequence sorted by the same ordering as the search. |
| x | object | Item to insert. |
| lo | int | Inclusive lower search bound. |
| hi | int or None | Exclusive upper search bound; None means length of sequence. |
| key | callable or None | Optional key function used for comparison or grouping. |
Return Value
None
No return value; the operation changes the receiver in place.
Working Example
Example Snippetpython
import bisecta=[1,2,2,4]bisect.insort_right(a,3)print(a)