all Python 3bisectfunction
bisect.bisect()
position
bisect.bisect() is an alias of bisect_right(). It returns the insertion position after any equal items.
Syntax
bisect.bisect(a, x) # то же что bisect_right
The choice between bisect and bisect_left only matters when duplicates exist: bisect_left(a, x) counts items strictly less than x, bisect(a, x) counts items less than or equal, and their difference is how many times x occurs. New code usually spells out bisect_right, so the reader can see which of the two boundaries is meant.
Examples
import bisect
a = [1, 2, 3, 3, 5]
bisect.bisect(a, 3) # → 4
bisect.bisect(a, 2.5) # → 2
bisect.bisect(a, 0) # → 0
bisect.bisect(a, 10) # → 5
See also
Open in the full glossarydocs.python.orgReport an inaccuracy