This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients mallika.bachan, rhettinger
Date 2021-05-31.19:03:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1622487834.52.0.636895558303.issue44227@roundup.psfhosted.org>
In-reply-to
Content
> 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
History
Date User Action Args
2021-05-31 19:03:54rhettingersetrecipients: + rhettinger, mallika.bachan
2021-05-31 19:03:54rhettingersetmessageid: <1622487834.52.0.636895558303.issue44227@roundup.psfhosted.org>
2021-05-31 19:03:54rhettingerlinkissue44227 messages
2021-05-31 19:03:54rhettingercreate