When are bisect_left and bisect_right not equal?

python, python-2.7

Solution

`bisect.bisect_left` returns the leftmost place in the sorted list to insert the given element. `bisect.bisect_right` returns the rightmost place in the sorted list to insert the given element.

An alternative question is when are they equivalent? By answering this, the answer to your question becomes clear.

They are equivalent when the the element to be inserted is not present in the list. Hence, they are not equivalent when the element to be inserted is in the list.

Problem

In my understanding, `bisect_left` and `bisect_right` are two different ways of doing the same thing: bisection, one coming from the left and the other coming from the right. Thus, it follows that they have the same result. Under what circumstances are these two not equal, i.e. when will they return different results, assuming the list and the value that is being searched are the same?

Original source