Re: [Tutor] manipulating list of lists

2005-10-25 Thread Kent Johnson
John Fouhy wrote: > On 25/10/05, Brian van den Broek <[EMAIL PROTECTED]> wrote: > >>To sort by the second item, try >> >> >>> def sort_by_second(sequence): >>decorated = [(x[1], x) for x in sequence] >>decorated.sort() >>return [x[1] for x in decorated] > > > With python2

Re: [Tutor] manipulating list of lists

2005-10-24 Thread Brian van den Broek
John Fouhy said unto the world upon 2005-10-24 22:18: > On 25/10/05, Brian van den Broek <[EMAIL PROTECTED]> wrote: > >>To sort by the second item, try >> >> >>> def sort_by_second(sequence): >>decorated = [(x[1], x) for x in sequence] >>decorated.sort() >>return [x[1] for

Re: [Tutor] manipulating list of lists

2005-10-24 Thread John Fouhy
On 25/10/05, Brian van den Broek <[EMAIL PROTECTED]> wrote: > To sort by the second item, try > > >>> def sort_by_second(sequence): > decorated = [(x[1], x) for x in sequence] > decorated.sort() > return [x[1] for x in decorated] With python2.4, you can use the key= argume

Re: [Tutor] manipulating list of lists

2005-10-24 Thread John Fouhy
On 25/10/05, Brian van den Broek <[EMAIL PROTECTED]> wrote: > To sort by the second item, try > > >>> def sort_by_second(sequence): > decorated = [(x[1], x) for x in sequence] > decorated.sort() > return [x[1] for x in decorated] With python2.4, you can use the key= argume

Re: [Tutor] manipulating list of lists

2005-10-24 Thread Brian van den Broek
Vincent Gulinao said unto the world upon 2005-10-24 09:29: > I have a list of lists of constant width (2 rows). I need to: > 1. delete sub-lists with None element > 2. sort it by any sub-list index > > say: [ ['c','d'], ['g',None], ['a','b',], ['e','f'] > if sorted using 2nd index: [ ['a','b'], ['