all Python 3bisectfunction
bisect.bisect_left()
position
Return the index at which to insert x into a sorted list keeping it sorted — before any equal entries. O(log n) search.
Syntax
bisect.bisect_left(a, x, lo=0, hi=len(a))
The list must already be sorted — nothing checks this, and on unsorted data you silently get a meaningless index. Also, the O(log n) covers the search only: inserting with insort is still O(n) because the tail of the list has to shift, so bisect does not turn a list into a fast sorted container when you insert a lot.
Examples
import bisect
a = [1, 3, 3, 5, 7]
bisect.bisect_left(a, 3) # → 1 (перед равными)
bisect.bisect_left(a, 4) # → 3
bisect.bisect_left(a, 8) # → 5
See also
Open in the full glossarydocs.python.orgReport an inaccuracy