New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sorting order of SortedList? #35
Comments
It does a length check first. It was designed to match the blist.sortedlist behavior: In [1]: import sortedcontainers as soco
In [2]: soco.SortedList([1, 2]) < [3]
Out[2]: False
In [3]: [1, 2] < [3]
Out[3]: True
In [4]: import blist
In [5]: blist.sortedlist([1, 2]) < [3]
Out[5]: False What did you expect the semantics to be? |
I don't know, anything else... matching the builtin list would make sense, even so if you can compare SortedLists with regular lists (and why wouldn't you?) The current behavior can be explained as an algorithm, but doesn't have meaning. What does it mean for the list to be bigger? My view is if the only way to explain is to detail the algorithm, the behavior doesn't make sense. You can make a greater list become smaller by strictly adding elements, so any intuitive inclusion-like meaning doesn't hold...
Does blist really use that? They state that Python's unittests pass with it... |
Also for reference, the CPython source: https://github.com/python/cpython/blob/master/Objects/listobject.c#L2225 I think
That's odd in its own ways but it has the advantage of defining a total ordering. I think that could be an important feature. Out of curiosity, why did you need to compare sorted lists? |
I've pushed an update for sortedcontainers.SortedList at dd06ac0. I think this mimics the "list" comparison behavior in CPython. I implemented a slightly weaker type-check by requiring only that each container inherits from I also believe I found a bug in the blist.sortedlist implementation. Details at DanielStutzbach/blist#77 These changes should also be applied to SortedListWithKey. |
Thanks! |
Out of curiosity, why did you need to compare sorted lists? |
I'm actually comparing a sorted list to a regular list. I'm using SortedList as a list that will eventually need to be sorted, that might be out of your use case. |
Fixed at 9816156. |
Deployed to PyPI in version 1.4.2 |
SortedList objects don't compare the same way lists do, or in any way that I could make sense of.
The text was updated successfully, but these errors were encountered: