On this page
bisect.bisect_left
Prev: bisect.bisect | Up: bisect | Next: bisect.bisect_right
Rel: bisect.bisect, bisect.bisect_right, bisect.insort, bisect.insort_left
Ref: docs.python.org — bisect.bisect_left
Tags: #public #python3 #stdlib #bisect
Import
import bisect
from bisect import bisect_left
Signature & Overview
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.
Usage
import bisect
arr = [10, 20, 20, 30]
idx = bisect.bisect_left(arr, 20)
assert idx == 1 and arr[idx] == 20
Gotchas
- Returns the leftmost insertion point: Best choice for exact binary-search membership checks (
i < len(arr) and arr[i] == target).
REPL Inspect
from bisect import bisect_left
help(bisect_left)
Linked from
Related notes
- tuts/python3/stdlib_module/bisect/bisect Linked here; links to this page; shared tags: #bisect, #stdlib
- tuts/python3/stdlib_module/bisect/bisect_right Linked here; links to this page; shared tags: #bisect, #stdlib
- tuts/python3/stdlib_module/bisect/insort Linked here; links to this page; shared tags: #bisect, #stdlib
- tuts/python3/stdlib_module/bisect/insort_left Linked here; links to this page; shared tags: #bisect, #stdlib
- tuts/python3/stdlib_module/bisect/insort_right links to this page; shared tags: #bisect, #stdlib
- tuts/python3/stdlib_module/bisect links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib