Looking for a different version of sort

David Eppstein eppstein at ics.uci.edu
Tue Jun 15 23:08:00 EDT 2004


In article <8a4484e4.0406151819.6c0538e7 at posting.google.com>,
 BigsyNY at yahoo.com (Brian McGonigle) wrote:

> I would like "list(t).sort()" to return a new sorted list. For
> example, then I could do "t = tuple(list(t).sort())" to simulate an
> in-place sort of a tuple assigned to the variable "t". When I try this
> now I get:

There are situations when you might want to sort tuples, but they're 
rare -- unless you need to use them as dict keys or something, it's more 
likely that you should just be using lists.

But I think the actual answer to your question is that a sorted() 
function is coming in Python 2.4 -- see e.g.
http://www.python.org/dev/doc/devel/whatsnew/node6.html
Once this is in place, you'd be able to do t = tuple(sorted(t))
without even turning it into a list first.

-- 
David Eppstein                      http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science



More information about the Python-list mailing list