>>> class C:
... def __len__(self):
... return 10
... def __getitem__(self, i):
... if i >= 10:
... raise IndexError('out of range')
... return i+1
...
>>> c = C()
>>> import bisect
>>> bisect.bisect_left(c, 1)
0
>>> bisect.bisect_left(c, 4)
3