You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ValueError when discarding values with changing sort value #239
I have the case, that I want to use a custom sort function when working with a SortedSet. The key provided by this function for each value may change, based on some external properties. I now ran into the problem, that when discarding keys from my Set, I get a ValueError:
File "/home/appuser/.pyenv/versions/3.11.7/lib/python3.11/site-packages/sortedcontainers/sortedlist.py", line 2031, in remove
raise ValueError('{0!r} not in list'.format(value))
To be honest, it took me several hours to figure out the cause of this which I believe is the fact, that the key values may change over time. I reproduced this with a simple example which uses random values:
File "/home/appuser/.pyenv/versions/3.11.7/lib/python3.11/site-packages/sortedcontainers/sortedlist.py", line 2031, in remove
raise ValueError('{0!r} not in list'.format(value))
ValueError: 0 not in list
I can somewhat understand that this may not be the exact use case intended for the sorted containers, and I could rebuild the whole SortedSet to work around this. However, it isn't really obvious to me why this happens when I just want to discard a value.
I encountered a similar error , but in SortedList.
I first searched for elements and then deleted the found elements. Has the problem you encountered been resolved.
`for e in self.events:
if e.obj is obj and e.name == name:
remove_list.append(e)
Activity
youhuiji commentedon Dec 22, 2024
I encountered a similar error , but in SortedList.
I first searched for elements and then deleted the found elements. Has the problem you encountered been resolved.
`for e in self.events:
if e.obj is obj and e.name == name:
remove_list.append(e)
for e in remove_list:
self.events.remove(e)`
olutra commentedon Jan 5, 2025
keyis used as a hash function, it must be deterministic.