[issue14542] reverse() doesn't reverse sort correctly

Mark Dickinson report at bugs.python.org
Wed Apr 11 14:28:56 CEST 2012


Mark Dickinson <dickinsm at gmail.com> added the comment:

Bill,

list.reverse doesn't do any *sorting* at all;  it merely *reverses* the list contents.

>>> x = [1, 3, 4, 2]
>>> x.reverse()
>>> x
[2, 4, 3, 1]

If you want to do a reverse sort, you can either first sort normally and then reverse the result, or (easier) use the 'reverse' keyword argument to the list.sort method, as follows:

>>> x = [1, 3, 4, 2]
>>> x.sort(reverse=True)
>>> x
[4, 3, 2, 1]

I suspect Eric meant to write "does not reverse sort" instead of "does not reverse".

----------
nosy: +mark.dickinson

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


More information about the Python-bugs-list mailing list