This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Sorting HOW TO: bad example for reverse sort stability
Type: enhancement Stage: commit review
Components: Documentation Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: docs@python, ezio.melotti, jwilk, python-dev, rhettinger
Priority: normal Keywords: patch

Created on 2015-07-25 09:51 by jwilk, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
reverse_stablity.diff rhettinger, 2015-07-25 19:34 Improve example
Messages (4)
msg247328 - (view) Author: Jakub Wilk (jwilk) Date: 2015-07-25 09:51
https://docs.python.org/3/howto/sorting.html#odd-and-ends gives the following example for reverse sort stability:

>>> data = [('red', 1), ('blue', 1), ('red', 2), ('blue', 2)]
>>> assert sorted(data, reverse=True) == list(reversed(sorted(reversed(data))))

But here all the keys are different, so the result would be the same even if the sort algorithm weren't stable.

You probably wanted to pass to key=itemgetter(0) to both sorted() calls.
msg257432 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2016-01-04 00:03
LGTM, however I would also show the sorted output too.
msg264231 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-04-26 08:09
New changeset ba87f7f246e0 by Raymond Hettinger in branch '2.7':
Issue #24715: Improve sort stability example
https://hg.python.org/cpython/rev/ba87f7f246e0
msg264232 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-04-26 08:11
New changeset ae1e55102449 by Raymond Hettinger in branch '3.5':
Issue #24715: Improve sort stability example
https://hg.python.org/cpython/rev/ae1e55102449
History
Date User Action Args
2022-04-11 14:58:19adminsetgithub: 68903
2016-04-26 08:11:50rhettingersetstatus: open -> closed
resolution: fixed
2016-04-26 08:11:35python-devsetmessages: + msg264232
2016-04-26 08:09:48python-devsetnosy: + python-dev
messages: + msg264231
2016-01-04 00:03:50ezio.melottisetversions: + Python 2.7, Python 3.5, Python 3.6
nosy: + ezio.melotti

messages: + msg257432

type: enhancement
stage: commit review
2015-07-25 19:34:11rhettingersetfiles: + reverse_stablity.diff
keywords: + patch
2015-07-25 16:42:52rhettingersetassignee: docs@python -> rhettinger

nosy: + rhettinger
2015-07-25 09:51:11jwilkcreate