You are viewing a single comment's thread from:
RE: Python Tricks #14 - Binary search is faster than linear
You could make it even a little faster by using the return True statement instead of done = True and remove done from the program by writing return False at the end. That way you don't need to test and not done every loop.
Also I think you meant to use last = mid-1 and
first = mid+1. Otherwise your program would be linear.
Thanks for your notes! Indeed it is more pytonic without
donevariable. I made corrections according to your suggestions. Thanks!