We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
sorted()
The sorted() function is not stable. Example:
>>> ids = [{"i": 0, "id": "ID: {0}".format(i)} for i in range(10)] >>> ids [{'i': 0, 'id': 'ID: 0'}, {'i': 0, 'id': 'ID: 1'}, {'i': 0, 'id': 'ID: 2'}, {'i': 0, 'id': 'ID: 3'}, {'i': 0, 'id': 'ID: 4'}, {'i': 0, 'id': 'ID: 5'}, {'i': 0, 'id': 'ID: 6'}, {'i': 0, 'id': 'ID: 7'}, {'i': 0, 'id': 'ID: 8'}, {'i': 0, 'id': 'ID: 9'}] >>> sorted(ids, key=lambda obj: obj['i']) [{'i': 0, 'id': 'ID: 6'}, {'i': 0, 'id': 'ID: 5'}, {'i': 0, 'id': 'ID: 9'}, {'i': 0, 'id': 'ID: 7'}, {'i': 0, 'id': 'ID: 8'}, {'i': 0, 'id': 'ID: 1'}, {'i': 0, 'id': 'ID: 0'}, {'i': 0, 'id': 'ID: 4'}, {'i': 0, 'id': 'ID: 2'}, {'i': 0, 'id': 'ID: 3'}]
In CPython:
>>> ids = [{"i": 0, "id": "ID: {0}".format(i)} for i in range(10)] >>> ids [{'i': 0, 'id': 'ID: 0'}, {'i': 0, 'id': 'ID: 1'}, {'i': 0, 'id': 'ID: 2'}, {'i': 0, 'id': 'ID: 3'}, {'i': 0, 'id': 'ID: 4'}, {'i': 0, 'id': 'ID: 5'}, {'i': 0, 'id': 'ID: 6'}, {'i': 0, 'id': 'ID: 7'}, {'i': 0, 'id': 'ID: 8'}, {'i': 0, 'id': 'ID: 9'}] >>> sorted(ids, key=lambda obj: obj['i']) [{'i': 0, 'id': 'ID: 0'}, {'i': 0, 'id': 'ID: 1'}, {'i': 0, 'id': 'ID: 2'}, {'i': 0, 'id': 'ID: 3'}, {'i': 0, 'id': 'ID: 4'}, {'i': 0, 'id': 'ID: 5'}, {'i': 0, 'id': 'ID: 6'}, {'i': 0, 'id': 'ID: 7'}, {'i': 0, 'id': 'ID: 8'}, {'i': 0, 'id': 'ID: 9'}]
The order of the IDs is ascending (unaffected) in CPython whereas it is shuffled in Pycopy.
The text was updated successfully, but these errors were encountered:
After doing some digging, it seems this is a known issue:
pycopy/py/objlist.c
Lines 343 to 344 in d590892
likely because of the use of quicksort instead of e.g. timsort:
Lines 361 to 363 in d590892
Sorry, something went wrong.
No branches or pull requests
The
sorted()
function is not stable. Example:In CPython:
The order of the IDs is ascending (unaffected) in CPython whereas it is shuffled in Pycopy.
The text was updated successfully, but these errors were encountered: