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
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
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
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
Thanks guys,
dirty hack was what I needed to get a job done quickly.
Nick
--
http://mail.python.org/mailman/listinfo/python-list
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],
[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]]
I
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
--
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):
#do
Taking
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.
--
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
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 would
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 always
[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 display. I
On Jan 31, 12:35 pm, Bruno Desthuilliers bruno.
[EMAIL PROTECTED] 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
Paddy a écrit :
On Jan 31, 12:35 pm, Bruno Desthuilliers bruno.
(snip)
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
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
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 records
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]y[2]) and call
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
[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. I do
Létezo [EMAIL PROTECTED] writes:
I then thought I'd just go events.sort(lambda x,y: x[2]y[2]) and call
Use:
events.sort(lambda x,y: cmp(x[2], y[2]))
or:
events.sort(key=lambda x: x[2])
--
http://mail.python.org/mailman/listinfo/python-list
21 matches
Mail list logo