Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

> Conceptually, yes, but the function does return an index,

The function does not return an index.  It returns an integer that represents 
an insertion point.  The documentation is clear about this:

    Locate the insertion point for x in a to maintain sorted order.
    ...
    return value is suitable for use as the first
    parameter to list.insert()

Likewise, the documented and precise invariants are stated in terms of slice 
points:

   The returned insertion point i partitions the array ``a ``
   into two halves so that ``all(val < x for val in a[lo : i])``
   for the left side and ``all(val >= x for val in a[i : hi])``
   for the right side.


> and values are stored at these indices.

That isn't true:

    >>> bisect([], 5)
    0

There is no value at 0.

The bisect functions are all about insertion points and ranges.  They aren't 
expressed in terms of an index and value.  The underlying algorithm never 
checks for equality.  Instead, it only uses __lt__(), so it is never aware of 
having "found" a value at all.

For people with use cases expressed in terms of index and value, there is a 
separate section of the docs showing show how to bridge between what they want 
and what the module actually does:

    https://docs.python.org/3.10/library/bisect.html#searching-sorted-lists

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44227>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to