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
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
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
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
Thanks guys,
"dirty hack" was what I needed to get a job done quickly.
Nick
--
http://mail.python.org/mailman/listinfo/python-list
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
>>> 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
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
> 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
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
> 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/
[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]]
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], ['
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(
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
[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
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
[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.
> 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
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
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
21 matches
Mail list logo