summaryrefslogtreecommitdiffstats
path: root/Doc/howto
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-04-26 08:11:28 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-04-26 08:11:28 (GMT)
commitc5c43b8374ced0e889cf90b6e1ff0cc4341dbb3a (patch)
tree3e1f6a8369d781e0e9e04005f23746ee5c3f5333 /Doc/howto
parentab425aa9d3353a15e2a673eb1af121dcde720a14 (diff)
parentb9531bcdcce35c443f1b7c6f1c79ed8ae575f36b (diff)
downloadcpython-c5c43b8374ced0e889cf90b6e1ff0cc4341dbb3a.zip
cpython-c5c43b8374ced0e889cf90b6e1ff0cc4341dbb3a.tar.gz
cpython-c5c43b8374ced0e889cf90b6e1ff0cc4341dbb3a.tar.bz2
merge
Diffstat (limited to 'Doc/howto')
-rw-r--r--Doc/howto/sorting.rst6
1 files changed, 5 insertions, 1 deletions
diff --git a/Doc/howto/sorting.rst b/Doc/howto/sorting.rst
index 10cb94c..0334b26 100644
--- a/Doc/howto/sorting.rst
+++ b/Doc/howto/sorting.rst
@@ -262,7 +262,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)]
* The sort routines are guaranteed to use :meth:`__lt__` when making comparisons
between two objects. So, it is easy to add a standard sort order to a class by