[Python-checkins] cpython (2.7): Issue #24715: Improve sort stability example
raymond.hettinger
python-checkins at python.org
Tue Apr 26 04:09:44 EDT 2016
https://hg.python.org/cpython/rev/ba87f7f246e0
changeset: 101151:ba87f7f246e0
branch: 2.7
user: Raymond Hettinger <python at rcn.com>
date: Tue Apr 26 01:09:32 2016 -0700
summary:
Issue #24715: Improve sort stability example
files:
Doc/howto/sorting.rst | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/Doc/howto/sorting.rst b/Doc/howto/sorting.rst
--- a/Doc/howto/sorting.rst
+++ b/Doc/howto/sorting.rst
@@ -274,7 +274,11 @@
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:
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list