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@python
components: Documentation
messages: 247328
nosy: docs@python, jwilk
priority: normal
severity: normal
status: open
title: Sorting HOW TO: bad example for reverse sort stability
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue24715>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com