Created
January 6, 2026 12:47
-
-
Save pythonhacker/161cef003adf677f257dbb611e29c59c to your computer and use it in GitHub Desktop.
Return the occurences of an element in a sorted list using bisect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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