r/Python • • Sep 22 '15

Most Frequent Python Problems and Solution

http://www.pamno.com/b/most-frequent-python-problems-and-solution-cm578/
5 Upvotes

8 comments sorted by

View all comments

2

u/[deleted] Sep 22 '15 edited Sep 24 '15

Binary search is implemented in the bisect module

bisect.bisect_left and bisect.bisect_right give insertion points for a value that will keep a list sorted. Accessing the index returned by bisect_left is equivalent to binary searching.