Tasks involving search in a sorted list are pretty common.
Sometimes using list literal would be very convenient and fast enough for small list, e.g., [v for v >= x for v in a]
.
However, when the list is too large, this kind of linear search can cost much time than it is actually needed. Using binary search is preffered in this situation.
Python has a built in library bisect
for this kind of job.
Sometimes it could be quite confusing how to use, though.
Here I tried to summary the basic usage and some useful application of bisect
.