Re: [Tutor] Newbie: Sorting lists of lists

2008-06-19 Thread Mark Tolonen
"Kent Johnson" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] On Wed, Jun 18, 2008 at 8:30 PM, Keith Troell <[EMAIL PROTECTED]> wrote: Let's say I have a list of lists l == [[1, 2, 3], [2, 3, 1], [3, 2, 1], [1, 3, 2]] If I do a l.sort(), it sorts on the first element of each lis

Re: [Tutor] Newbie: Sorting lists of lists

2008-06-19 Thread Kent Johnson
On Wed, Jun 18, 2008 at 10:48 PM, Forrest Y. Yu <[EMAIL PROTECTED]> wrote: > I know, it's NOT beautiful code, but it seems work. If you have no better > way, try this: > > """Sort on the second elements.""" > def xchg12(l) : > for m in l: > m[0], m[1] = m[1], m[0] > > l = [[1, 2, 3], [2

Re: [Tutor] Newbie: Sorting lists of lists

2008-06-18 Thread Forrest Y. Yu
> > Message: 8 > Date: Wed, 18 Jun 2008 19:30:05 -0500 > From: Keith Troell <[EMAIL PROTECTED]> > Subject: [Tutor] Newbie: Sorting lists of lists > To: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=US-ASCII; delsp=yes;

Re: [Tutor] Newbie: Sorting lists of lists

2008-06-18 Thread Kent Johnson
On Wed, Jun 18, 2008 at 8:30 PM, Keith Troell <[EMAIL PROTECTED]> wrote: > Let's say I have a list of lists l == [[1, 2, 3], [2, 3, 1], [3, 2, 1], [1, > 3, 2]] > > If I do a l.sort(), it sorts on the first element of each listed list: > l.sort() l > [[1, 2, 3], [1, 3, 2], [2, 3, 1], [3, 2

Re: [Tutor] Newbie: Sorting lists of lists

2008-06-18 Thread John Fouhy
On 19/06/2008, Keith Troell <[EMAIL PROTECTED]> wrote: > Let's say I have a list of lists l == [[1, 2, 3], [2, 3, 1], [3, 2, 1], [1, > 3, 2]] > > If I do a l.sort(), it sorts on the first element of each listed list: > > >>> l.sort() > >>> l > [[1, 2, 3], [1, 3, 2], [2, 3, 1], [3, 2, 1]] > > >

[Tutor] Newbie: Sorting lists of lists

2008-06-18 Thread Keith Troell
Let's say I have a list of lists l == [[1, 2, 3], [2, 3, 1], [3, 2, 1], [1, 3, 2]] If I do a l.sort(), it sorts on the first element of each listed list: >>> l.sort() >>> l [[1, 2, 3], [1, 3, 2], [2, 3, 1], [3, 2, 1]] How can I sort on the second or third elements of the listed lists? Keith