If you want to bisect a slice, then bisect a slice:
result = bisect_right(a[lo:hi], x)
Oh, wait, what if a has billions of elements and creating a slice
containing a million or two out of the middle is too expensive?
Yup, that's why Iproposed about a year ago on this list that there should be a way to get a slice view (or slice iterator, AKA islice) easily :-)
You can use itertools.islice for this though -- oops, no you can't:
TypeError Traceback (most recent call last)
<ipython-input-36-9efe49979a8e> in <module>
----> 1 result = bisect.bisect_right(islice(a, lo, hi), x)
TypeError: object of type 'itertools.islice' has no len()
We really do need a slice view :-)
-CHB
-- Christopher Barker, PhD (Chris)
Python Language Consulting
- Teaching
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython