On 12/08/2010 03:47 AM, Steven D'Aprano wrote:
Or a list that needs to be presented to a human reader in some arbitrary
but consistent order.
Or a doctest that needs to show the keys in a dict:
>>> d = myfunction()
>>> sorted(d.keys())
['ham', 'spam', 42, None]
[snip]
Agreed, but in hindsight I think it would be better if there was a
separate lexicographic sort function, that guaranteed to sort anything
(including such unorderable values as complex numbers!), without relying
on the vagaries of the standard comparison operators.
wouldn't that be something like
sorted(mixedstuff, key=str)
or if all you need is a stable order regardless of what that
order is, one could even get away with:
sorted(mixedstuff, key=id)
-tkc
--
http://mail.python.org/mailman/listinfo/python-list