Skip to content

Instantly share code, notes, and snippets.

@pythonhacker
Created January 6, 2026 12:24
Show Gist options
  • Select an option

  • Save pythonhacker/f9868683e257a695dfe32624c515e1a0 to your computer and use it in GitHub Desktop.

Select an option

Save pythonhacker/f9868683e257a695dfe32624c515e1a0 to your computer and use it in GitHub Desktop.
Demo of binary search using bisect
>>> l = [10, 15, 18, 20, 21, 21, 21, 24, 24]
>>> binary_search(l, 18)
2
>>> binary_search(l, 21)
4
>>> binary_search(l, 24)
7
>>> binary_search(l, 100)
-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment