Closed figura-equi closed 1 year ago
from sortedcontainers import SortedList class MySortableClass: def __init__(self, value): self.value = value def __lt__(self, other): return self.value < other.value def test_sorted_list_remove(): sorted_list = SortedList() item_1 = MySortableClass(1) item_2 = MySortableClass(1) sorted_list.add(item_1) sorted_list.add(item_2) sorted_list.remove(item_2)
Fails with ValueError (not in list), because remove finds the position 0 and then sees the object on position 0 is different.
ValueError
You haven’t defined equality correctly. See https://grantjenks.com/docs/sortedcontainers/introduction.html#caveats
Fails with
ValueError
(not in list), because remove finds the position 0 and then sees the object on position 0 is different.