Open this example in the interactive library
Source code
from bisect import bisect_left, bisect_right
values = [1, 3, 3, 7]
print(list(range(bisect_left(values, 3), bisect_right(values, 3))))Sample output
[1, 2]

Search a sorted collection for all matching positions in Python.
Open this example in the interactive library
from bisect import bisect_left, bisect_right
values = [1, 3, 3, 7]
print(list(range(bisect_left(values, 3), bisect_right(values, 3))))[1, 2]