Skip to content

Instantly share code, notes, and snippets.

@JasonTam
Last active February 28, 2018 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JasonTam/ab3d23ed9a0c4bbc4abf504f3ea6c91b to your computer and use it in GitHub Desktop.
Save JasonTam/ab3d23ed9a0c4bbc4abf504f3ea6c91b to your computer and use it in GitHub Desktop.
Most of the time `in` is good enough (even for lists)
from bisect import bisect_left
def in_bs(a, x):
i = bisect_left(a, x)
return (i != len(a)) and (a[i] == x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment