Raymond Hettinger <[email protected]> added the comment:
I there is a misunderstanding here. The bisect functions never point *to* a
value. Instead, they are documented to return "insertion points". Those
always occur just before or after a specific value:
values: 10 20 30 30 30 40 50
insertion points: | | | | | | | |
0 1 2 3 4 5 6 7
bisect_left(30) -------------^
bisect_right(30) ---------------------------^
As you can see, bisect_left() does in fact point JUST BEFORE the 30.
Note this is also how slicing works. Here's an example:
>>> from bisect import bisect_left, bisect_right
>>> s = [10, 20, 30, 30, 30, 40, 50]
>>> i = bisect_left(s, 30)
>>> j = bisect_right(s, 30)
>>> s[i : j]
[30, 30, 30]
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue44227>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com