Issue #24715: Improve sort stability example
This commit is contained in:
parent
167c81d5ed
commit
ff64b3a532
|
@ -274,7 +274,11 @@ Odd and Ends
|
||||||
twice:
|
twice:
|
||||||
|
|
||||||
>>> data = [('red', 1), ('blue', 1), ('red', 2), ('blue', 2)]
|
>>> data = [('red', 1), ('blue', 1), ('red', 2), ('blue', 2)]
|
||||||
>>> assert sorted(data, reverse=True) == list(reversed(sorted(reversed(data))))
|
>>> standard_way = sorted(data, key=itemgetter(0), reverse=True)
|
||||||
|
>>> double_reversed = list(reversed(sorted(reversed(data), key=itemgetter(0))))
|
||||||
|
>>> assert standard_way == double_reversed
|
||||||
|
>>> standard_way
|
||||||
|
[('red', 1), ('red', 2), ('blue', 1), ('blue', 2)]
|
||||||
|
|
||||||
* To create a standard sort order for a class, just add the appropriate rich
|
* To create a standard sort order for a class, just add the appropriate rich
|
||||||
comparison methods:
|
comparison methods:
|
||||||
|
|
Loading…
Reference in New Issue