[Raymond Bisdorff <raymond.bisdorff@pt.lu>]
... 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')]
Looks good to me.
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')]
Stability is irrelevant in the example, because no two list elements are equal. You appear to be thinking, perhaps, that s[0] == t[0] when s == (1, 'a') and t == (1, 'c') means s and t "are equal", but that's not so at all.
s = (1, 'a') t = (1, 'c') s == t False s < t True t > s True
So s MUST come before t in a forward sort, and t MUST come before s in a reverse sort.