On 10/30/21 11:46 AM, Raymond Bisdorff wrote:
Dear Python developers,
The help(list) shows in a python console the following documentation
string for the list.sort() method.
sort(self, /, *, key=None, reverse=False)
| Sort the list in ascending order and return None.
|
| The sort is in-place (i.e. the list itself is modified) and
stable (i.e. the
| order of two equal elements is **maintained**).
Please notice the following inconsistency in Python3.10.0 and before
of a sort(reverse=True) result:
>>> L = [(1, 'a'), (2, 'b'), (1, 'c'), (2, 'd'), (3, 'e')]
>>> L.sort(reverse=True)
>>> L
>>> [(3, 'e'), (2, 'd'), (2, 'b'), (1, 'c'), (1, 'a')]
it should be:
>>> L = [(1, 'a'), (2, 'b'), (1, 'c'), (2, 'd'), (3, 'e')]
>>> reverseTuplesSort(L)
[(3, 'e'), (2, 'b'), (2, 'd'), (1, 'a'), (1, 'c')]
Same inconsistency appears when using a sorting key.
Passing easily unnoticed may produce unexpected and potentially wrong
ranking results.
Best Regards,
RB
Why do you thing (1,'a') should be 'bigger' than (1, 'c'), or (2,'b')
bigger than (2,'d')?
Tuples don't sort on just the first element, but on all their elements
in order if the previous ones are the same.
--
Richard Damon
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/HHW6YZOYPSN4JXBEKHCI73TKDM4CPWWB/
Code of Conduct: http://python.org/psf/codeofconduct/