# pydoc > _bisect

---
type: CommandReference
command: _bisect
mode: pydoc
section: 
source: pydoc3
---

## Quick Reference

- `bisect_left(a, x, lo=0, hi=len(a))` — Return index to insert `x` before any existing match.
- `bisect_right(a, x, lo=0, hi=len(a))` — Return index to insert `x` after any existing match.
- `insort_left(a, x, lo=0, hi=len(a))` — Insert `x` into sorted list `a` to the left of equal elements.
- `insort_right(a, x, lo=0, hi=len(a))` — Insert `x` into sorted list `a` to the right of equal elements.

## Name

Bisection algorithms — maintain a sorted list without re-sorting after each insertion.

## Synopsis

python
bisect_left(a, x, lo=0, hi=len(a))
bisect_right(a, x, lo=0, hi=len(a))
insort_left(a, x, lo=0, hi=len(a))
insort_right(a, x, lo=0, hi=len(a))
## Options

- `lo` — Start index of the slice to search (default 0).
- `hi` — End index of the slice to search (default `len(a)`).

## Examples

python
import _bisect

a = [1, 3, 3, 5, 7]

# bisect_left: insert before leftmost 3
i = _bisect.bisect_left(a, 3)   # i = 1
a.insert(i, 3)                  # a -> [1, 3, 3, 3, 5, 7]

# bisect_right: insert after rightmost 3
i = _bisect.bisect_right(a, 3)  # i = 4
a.insert(i, 3)                  # a -> [1, 3, 3, 3, 3, 5, 7]

# insort_left: insert keeping order, left of equal
_bisect.insort_left(a, 4)       # a -> [1, 3, 3, 3, 3, 4, 5, 7]

# insort_right: insert keeping order, right of equal
_bisect.insort_right(a, 6)      # a -> [1, 3, 3, 3, 3, 4, 5, 6, 7]
## See Also

- Python `bisect` module — public interface to these functions.