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 temporaril
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 so
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 descendi
[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:
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:
L.sort(key=attrge
> 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:
> 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
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?
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 fa
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 descendi
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
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 negat
12 matches
Mail list logo