Note that that finds the index to the left of the insertion point for the value given, but doesn’t perform a containment test; you have to also check that the index is in the list (instead of off the end) and that the value at the resulting index equals the value of interest to test containment. Which can be a one-liner without redundant calls (with walrus), but is a bit ugly.
(Of course, for a custom class you can just wrap it in a __contains__ method and then just use the “in” operator.)
> you have to also check that the index is in the list (instead of off the end) and that the value at the resulting index equals the value of interest to test containment
True. However, the hardest part of the binary search algorithm is implemented through bisect, so it still saves a lot of developer time.
(Of course, for a custom class you can just wrap it in a __contains__ method and then just use the “in” operator.)