Re: Sorting lists

2008-11-17 Thread Steven D'Aprano
On Mon, 17 Nov 2008 14:36:03 -0500, Terry Reedy wrote: > [EMAIL PROTECTED] wrote: >> Chris Rebert: >>> You use the `key` argument to .sort(): L2.sort(key=lambda item: >>> item[1]) >> >> I like the lambda because it's a very readable solution that doesn't >> require the std lib and it doesn't forc

Re: Sorting lists

2008-11-17 Thread Terry Reedy
[EMAIL PROTECTED] wrote: Chris Rebert: You use the `key` argument to .sort(): L2.sort(key=lambda item: item[1]) I like the lambda because it's a very readable solution that doesn't require the std lib and it doesn't force the programmer (and the person that reads the code) to learn yet another

Re: Sorting lists

2008-11-17 Thread bearophileHUGS
Chris Rebert: > You use the `key` argument to .sort(): > L2.sort(key=lambda item: item[1]) I like the lambda because it's a very readable solution that doesn't require the std lib and it doesn't force the programmer (and the person that reads the code) to learn yet another thing/function. But I c

Re: Sorting lists

2008-11-17 Thread John Machin
On Nov 17, 8:56 pm, asc <[EMAIL PROTECTED]> wrote: > But my problem is this. I have a list, that contains a number of > embeded lists; > e.g. L2 = [['something', 'bb'], ['somethingElse', 'cc'], > ['anotherThing', 'aa']] > Now I want to sort this list by the second item of each sublist. So > the ou

Re: Sorting lists

2008-11-17 Thread Chris Rebert
On Mon, Nov 17, 2008 at 1:56 AM, asc <[EMAIL PROTECTED]> wrote: > Hi all, > I have a problem and I'm not sure whether sort() can help me. > I understand that if I have a list; say L = ['b', 'c', 'a'] > I can use L.sort() and I will then have; L = ['a', 'b', 'c'] > > But my problem is this. I have a