[Tutor] sorting tuples

Raymond Hettinger python@rcn.com
Mon, 20 May 2002 10:35:17 -0400


Convert the outer tuple to a list so that it can be sorted:

>>> a = ((4,1,8), (9,2,5),(3,6,9))
>>> b = list(a)
>>> b.sort()
>>> a = tuple(b)
>>> print a
((3, 6, 9), (4, 1, 8), (9, 2, 5))


Raymond Hettinger

----- Original Message ----- 
From: "Maximiliano Ichazo" <max_ig@yahoo.com>
To: <tutor@python.org>
Sent: Monday, May 20, 2002 9:55 AM
Subject: [Tutor] sorting tuples


> I have the following problem with tuples: 
> 
> I have a tuple with tuples in it (these sub-tuples have three items
> each). I want to sort the items of the main tuple based on the first
> item of the sub-tuples. However I don't know how can I do this.
> 
> Thanks in advance.
> 
> Max
> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> LAUNCH - Your Yahoo! Music Experience
> http://launch.yahoo.com
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>