Re: Sorting in reverse is not the same as sorting then reversing

2015-06-05 Thread Skip Montanaro
On Fri, Jun 5, 2015 at 9:50 AM, Stefan Behnel wrote: > [Stable sorting is] a general property of Python's sort algorithm. And at times an extremely valuable property. Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: Sorting in reverse is not the same as sorting then reversing

2015-06-05 Thread Peter Otten
Steven D'Aprano wrote: > Sorting in reverse does not give the same result as sorting then > reversing. > > It's easiest to see with a key function: > > > py> a = ['fox', 'dog', 'DOG', 'cat', 'ape'] > py> b = a[:] > py> a.sort(key=str.lower, reverse=True) > py> b.sort(key=str.lower) > py> b.reve

Re: Sorting in reverse is not the same as sorting then reversing

2015-06-05 Thread Stefan Behnel
Steven D'Aprano schrieb am 05.06.2015 um 16:07: > Sorting in reverse does not give the same result as sorting then reversing. > > It's easiest to see with a key function: > > py> a = ['fox', 'dog', 'DOG', 'cat', 'ape'] > py> b = a[:] > py> a.sort(key=str.lower, reverse=True) > py> b.sort(key=str.

Sorting in reverse is not the same as sorting then reversing

2015-06-05 Thread Steven D'Aprano
Sorting in reverse does not give the same result as sorting then reversing. It's easiest to see with a key function: py> a = ['fox', 'dog', 'DOG', 'cat', 'ape'] py> b = a[:] py> a.sort(key=str.lower, reverse=True) py> b.sort(key=str.lower) py> b.reverse() py> a ['fox', 'dog', 'DOG', 'cat', 'ape'