]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #24715: Improve sort stability example
authorRaymond Hettinger <python@rcn.com>
Tue, 26 Apr 2016 08:09:32 +0000 (01:09 -0700)
committerRaymond Hettinger <python@rcn.com>
Tue, 26 Apr 2016 08:09:32 +0000 (01:09 -0700)
Doc/howto/sorting.rst

index b501e0e1a401c7c48dd5c5b54a59b48f1b323f89..675ed97a777a3a4a896175198980a65ed89fd975 100644 (file)
@@ -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: