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']
py> b
['fox', 'DOG', 'dog', 'cat', 'ape']


Sorting in reverse keeps the initial order of any equal elements unchanged.
Sorting, then reversing, reverses them.


(Thanks to Tim Peters for the tip.)


-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to