Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save pythonhacker/161cef003adf677f257dbb611e29c59c to your computer and use it in GitHub Desktop.
Return the occurences of an element in a sorted list using bisect
def occurs(a, x):
""" Return all occurrences of x in a """
start = search(a, x)
end = search_right(a, x)
if start != -1 and end != -1:
return range(start, end, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment