Re: Sorting a list of lists

2010-02-13 Thread R (Chandra) Chandrasekhar
MRAB wrote: You'd have to post an example of that, but you could try deleting some of the entries before sorting so see whether you can still reproduce the problem with a smaller list. John Posner wrote: Please cut-and-paste the exact error message (or other evidence of "failure") into a mess

Re: Sorting a list of lists

2010-02-12 Thread John Posner
On 2/12/2010 12:45 PM, R (Chandra) Chandrasekhar wrote: Dear Folks, I have lines of values like so: 14, [25, 105, 104] 10, [107, 106, 162] 21, [26, 116, 165] I need to sort them in two ways: (a) By the numeric value of the first column; and (b) by the sum of the elements of the second item i

Re: Sorting a list of lists

2010-02-12 Thread MRAB
R (Chandra) Chandrasekhar wrote: Dear Folks, I have lines of values like so: 14, [25, 105, 104] 10, [107, 106, 162] 21, [26, 116, 165] I need to sort them in two ways: (a) By the numeric value of the first column; and (b) by the sum of the elements of the second item in each list, which is

Sorting a list of lists

2010-02-12 Thread R (Chandra) Chandrasekhar
Dear Folks, I have lines of values like so: 14, [25, 105, 104] 10, [107, 106, 162] 21, [26, 116, 165] I need to sort them in two ways: (a) By the numeric value of the first column; and (b) by the sum of the elements of the second item in each list, which is a list in itself. At present, I

Re: sorting a list of lists

2007-08-28 Thread nicksavill
Thanks guys, "dirty hack" was what I needed to get a job done quickly. Nick -- http://mail.python.org/mailman/listinfo/python-list

Re: sorting a list of lists

2007-08-27 Thread Gabriel Genellina
En Mon, 27 Aug 2007 15:41:15 -0300, iapain <[EMAIL PROTECTED]> escribi�: >> Taking advantage of stable sorting is totally not a hack. The OP just >> tried >> the two sorting steps in the wrong order. > > I didnt say not to use stable sorting, but write a generic function > and hacky code. It is

Re: sorting a list of lists

2007-08-27 Thread Tuomas
>>> records = [['dog',1,2], ['chair',2,1], ['cat',1,3], ['horse',3,4], ... ['table',3,2], ['window',3,5]] >>> sorted(records, key = lambda x: (x[1], x[2])) [['dog', 1, 2], ['cat', 1, 3], ['chair', 2, 1], ['table', 3, 2], ['horse', 3, 4], ['window', 3, 5]] [EMAIL PROTECTED] wrote: > Hi, > > i

Re: sorting a list of lists

2007-08-27 Thread [EMAIL PROTECTED]
On Aug 27, 2:41 pm, iapain <[EMAIL PROTECTED]> wrote: > ... It is always better to adopt a generic approach. The above statement is incorrect. -- http://mail.python.org/mailman/listinfo/python-list

Re: sorting a list of lists

2007-08-27 Thread iapain
> Taking advantage of stable sorting is totally not a hack. The OP just tried > the two sorting steps in the wrong order. I didnt say not to use stable sorting, but write a generic function and hacky code. It is always better to adopt a generic approach. -- http://mail.python.org/mailman/listin

Re: sorting a list of lists

2007-08-27 Thread Stefan Behnel
iapain wrote: >> i would like to sort a list of lists. The list is first sorted on the >> second item in the sub-lists (which I can do), then on the third item >> (which I can't). > > Write a comparator instead of dirty hacks > > mylistoflist.sort(mycomparator) > > def mycomparator(a, b): > #d

Re: sorting a list of lists

2007-08-27 Thread iapain
> i would like to sort a list of lists. The list is first sorted on the > second item in the sub-lists (which I can do), then on the third item > (which I can't). Write a comparator instead of dirty hacks mylistoflist.sort(mycomparator) def mycomparator(a, b): #do -- http://mail.python.org/

Re: sorting a list of lists

2007-08-27 Thread Peter Otten
[EMAIL PROTECTED] wrote: > i would like to sort a list of lists. The list is first sorted on the > second item in the sub-lists (which I can do), then on the third item > (which I can't). > > eg. records = [['dog',1,2], ['chair',2,1], ['cat',1,3], ['horse',3,4], > ['table',3,2], ['window',3,5]]

sorting a list of lists

2007-08-27 Thread nicksavill
Hi, i would like to sort a list of lists. The list is first sorted on the second item in the sub-lists (which I can do), then on the third item (which I can't). eg. records = [['dog',1,2], ['chair',2,1], ['cat',1,3], ['horse',3,4], ['table',3,2], ['window',3,5]] I want sorted to [['dog',1,2], ['

Re: Sorting a List of Lists

2007-01-31 Thread Bruno Desthuilliers
Paddy a écrit : > On Jan 31, 12:35 pm, Bruno Desthuilliers >Also, using comparison functions is usually not the most efficient way >>to do such a sort. In your case, I'd go for a good old >>Decorate/sort/undecorate (AKA schwarzian transform): >> >>events = [evt for date, evt in >> sorted(

Re: Sorting a List of Lists

2007-01-31 Thread Paddy
On Jan 31, 12:35 pm, Bruno Desthuilliers wrote: > [EMAIL PROTECTED] a écrit : > > > I can't seem to get this nailed down and I thought I'd toss it out > > there as, by gosh, its got to be something simple I'm missing. > > > I have two different database tables of events that use different > > sche

Re: Sorting a List of Lists

2007-01-31 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > I can't seem to get this nailed down and I thought I'd toss it out > there as, by gosh, its got to be something simple I'm missing. > > I have two different database tables of events that use different > schemas. I am using python to collate these records for displa

Re: Sorting a List of Lists

2007-01-30 Thread Paul Rubin
Létezo <[EMAIL PROTECTED]> writes: > > I then thought I'd just go events.sort(lambda x,y: x[2]http://mail.python.org/mailman/listinfo/python-list

Re: Sorting a List of Lists

2007-01-30 Thread Larry Bates
[EMAIL PROTECTED] wrote: > I can't seem to get this nailed down and I thought I'd toss it out > there as, by gosh, its got to be something simple I'm missing. > > I have two different database tables of events that use different > schemas. I am using python to collate these records for display.

Re: Sorting a List of Lists

2007-01-30 Thread Létezo
> events = [['Event URL as String', 'Event Title as String ', Event Date > as Datetime], ...] > > I then thought I'd just go events.sort(lambda x,y: x[2] it a day. That didn't work. But then lamda functions like to be very > simple, maybe object subscripts aren't allowed (even though I didn't > get

Re: Sorting a List of Lists

2007-01-30 Thread Thomas Nelson
On Jan 30, 5:55 pm, [EMAIL PROTECTED] wrote: > I can't seem to get this nailed down and I thought I'd toss it out > there as, by gosh, its got to be something simple I'm missing. > > I have two different database tables of events that use different > schemas. I am using python to collate these reco

Sorting a List of Lists

2007-01-30 Thread apotheos
I can't seem to get this nailed down and I thought I'd toss it out there as, by gosh, its got to be something simple I'm missing. I have two different database tables of events that use different schemas. I am using python to collate these records for display. I do this by creating a list of li