[docs] [issue24715] Sorting HOW TO: bad example for reverse sort stability

Jakub Wilk report at bugs.python.org
Sat Jul 25 11:51:11 CEST 2015


New submission from Jakub Wilk:

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.

----------
assignee: docs at python
components: Documentation
messages: 247328
nosy: docs at python, jwilk
priority: normal
severity: normal
status: open
title: Sorting HOW TO: bad example for reverse sort stability

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24715>
_______________________________________


More information about the docs mailing list