Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save pythonhacker/f2c83a2d91ae792516fc24a997d8d5a4 to your computer and use it in GitHub Desktop.
Demo of the occurrences function using bisect
>>> l=[10, 12, 15, 17, 18, 20, 20, 21, 21, 21, 24, 24]
>>> occurs(l, 18)
range(4, 5)
>>> occurs(l, 20)
range(5, 7)
>>> list(occurs(l, 21))
[7, 8, 9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment