python-sortedcontainers
python-sortedcontainers copied to clipboard
Feature Request: Add `key` parameter to bisect_left and bisect_right
Python 3.10 introduced the key parameter to their bisect functions. See for example https://docs.python.org/3/library/bisect.html#bisect.bisect_left
This allows one to bisect lists with values that cannot otherwise be compared directly.
It would be really awesome if the likes of SortedList.bisect_left
also accepted this argument passed it down to the standard library bisect_*
calls. For example here: https://github.com/grantjenks/python-sortedcontainers/blob/dff7ef79a21b3f3ceb6a19868f302f0a680aa243/sortedcontainers/sortedlist.py#L1166
It is only supported in python 3.10 though...
SortedKeyList already provides bisect_key_left and bisect_key_right https://github.com/grantjenks/python-sortedcontainers/blob/dff7ef79a21b3f3ceb6a19868f302f0a680aa243/sortedcontainers/sortedlist.py#L2282
Ordering elements by key requires additional index structures internally. Specifying different key functions would require building a new sorted list. I’m not sure how the new API in Python 3.10 would benefit the project.