Great post! I will practice the new coding style in the future.
Beibin Li
1

Hey great point! The ways I mentioned in the article doesn’t work well in this case because of the recursive nature of binary search. It’s easier to write it using recursion or while-loop, or even simpler, Python’s built-in module bisect:

>>> from bisect import bisect_left
>>> bisect_left([1, 2, 4, 7, 8, 9], 4)
2

Hope this is helpful for you

Like what you read? Give Randy Daw-Ran Liou a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.