diff options
author | Raymond Hettinger <python@rcn.com> | 2016-04-26 08:09:32 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2016-04-26 08:09:32 (GMT) |
commit | ff64b3a532cadf8d109f5a7e44cc226e61df630f (patch) | |
tree | 488aa0677628c5896607fe05ffb22ff4c450cc4d /Doc | |
parent | 167c81d5ed5a56a6f05a0786db483b2b73a55a45 (diff) | |
download | cpython-ff64b3a532cadf8d109f5a7e44cc226e61df630f.zip cpython-ff64b3a532cadf8d109f5a7e44cc226e61df630f.tar.gz cpython-ff64b3a532cadf8d109f5a7e44cc226e61df630f.tar.bz2 |
Issue #24715: Improve sort stability example
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/howto/sorting.rst | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Doc/howto/sorting.rst b/Doc/howto/sorting.rst index b501e0e..675ed97 100644 --- a/Doc/howto/sorting.rst +++ b/Doc/howto/sorting.rst @@ -274,7 +274,11 @@ Odd and Ends twice: >>> 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 comparison methods: |