[EMAIL PROTECTED] a écrit :
Raymond Hettinger:
The simplest way is to take advantage of sort-stability and do
successive sorts. For example, to sort by a primary key ascending and
a secondary key decending:
L.sort(key=lambda r: r.secondary, reverse=True)
L.sort(key=lambda r:
On 2007-01-03, dwelden [EMAIL PROTECTED] wrote:
I have successfully used the sort lambda construct described in
http://mail.python.org/pipermail/python-list/2006-April/377443.html.
However, how do I take it one step further such that some
values can be sorted ascending and others descending?
Neil Cerutti wrote:
Another trick is to factor the key application out of the sort.
This may be a good idea if when you want to minimize the number
of times your key function is called.
The idea is to mangle the list temporarily so you can use an
unkeyed sort, and then unmangle the sorted
On 2007-01-04, Peter Otten [EMAIL PROTECTED] wrote:
Neil Cerutti wrote:
Another trick is to factor the key application out of the
sort. This may be a good idea if when you want to minimize the
number of times your key function is called.
The idea is to mangle the list temporarily so you can
I have successfully used the sort lambda construct described in
http://mail.python.org/pipermail/python-list/2006-April/377443.html.
However, how do I take it one step further such that some values can be
sorted ascending and others descending? Easy enough if the sort values
are numeric (just
dwelden wrote:
I have successfully used the sort lambda construct described in
http://mail.python.org/pipermail/python-list/2006-April/377443.html.
However, how do I take it one step further such that some values can be
sorted ascending and others descending? Easy enough if the sort values
On Wed, 2007-01-03 at 10:48 -0800, dwelden wrote:
I have successfully used the sort lambda construct described in
http://mail.python.org/pipermail/python-list/2006-April/377443.html.
However, how do I take it one step further such that some values can be
sorted ascending and others descending?
Raymond Hettinger:
The simplest way is to take advantage of sort-stability and do
successive sorts. For example, to sort by a primary key ascending and
a secondary key decending:
L.sort(key=lambda r: r.secondary, reverse=True)
L.sort(key=lambda r: r.primary)
That's probably the faster
Raymond Hettinger wrote:
dwelden wrote:
I have successfully used the sort lambda construct described in
http://mail.python.org/pipermail/python-list/2006-April/377443.html.
However, how do I take it one step further such that some values can be
sorted ascending and others descending? Easy
dwelden wrote:
I have successfully used the sort lambda construct described in
http://mail.python.org/pipermail/python-list/2006-April/377443.html.
However, how do I take it one step further such that some values can be
sorted ascending and others descending? Easy enough if the sort values
The simplest way is to take advantage of sort-stability and do
successive sorts. For example, to sort by a primary key ascending and
a secondary key decending:
L.sort(key=lambda r: r.secondary, reverse=True)
L.sort(key=lambda r: r.primary)
Excellent! That looks just like what I
dwelden wrote:
L.sort(key=lambda r: r.secondary, reverse=True)
L.sort(key=lambda r: r.primary)
Excellent! That looks just like what I needed.
Note that there is the (probably little used) operator.attrgetter()
too, with that you can avoid the possibly slow lambda:
12 matches
Mail list logo