-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
On 13/03/11 13:14, Paul Moore wrote:
> None of my real code is affected either way, but it seems to me that
> the removal of the comparison function option was (sadly) a case of
> purity being allowed to beat practicality. Luckily, adding it back
> wou
On 3/13/2011 2:05 PM, Daniel Stutzbach wrote:
On Sat, Mar 12, 2011 at 3:44 PM, Guido van Rossum mailto:gu...@python.org>> wrote:
I recently advised a Googler who was sorting a large dataset and
running out of memory. My analysis of the situation was that he was
sorting a huge list of
On Sat, Mar 12, 2011 at 9:17 PM, Terry Reedy wrote:
> But in this case, they are much slower. To be faster, one would need
> something like "key=lambda p,q:p*(lcm//q)", where lcm is the least common
> multiple of of all the q's (denominators). For the example above, lcm = 700.
> But for longer li
On Sat, Mar 12, 2011 at 3:44 PM, Guido van Rossum wrote:
> I recently advised a Googler who was sorting a large dataset and
> running out of memory. My analysis of the situation was that he was
> sorting a huge list of short lines of the form "shortstring,integer"
> with a key function that retur
On 13 March 2011 03:00, Raymond Hettinger wrote:
>> But in Python 3 this solution is no longer available. How bad is that?
>> I'm not sure. But I'd like to at least get the issue out in the open.
>>
>
> Python3.2 should be substantially better in this regard.
> It no longer wraps key objects aroun
On 3/12/2011 10:52 PM, Glenn Linderman wrote:
On 3/12/2011 7:21 PM, Terry Reedy wrote:
The safest such character is \0,\
Works fine in Python.
unless you are coding in C,
Then \01 is next best.
I wouldn't have called you on this, except that it really is important
not to give people th
On 3/12/2011 7:21 PM, Terry Reedy wrote:
(Ok, I assumed that the 'word' field does not include any of
!"#$%&'()*+. If that is not true, replace comma with space or even a
control char such as '\a' which even precedes \t and \n.)
OK, I agree the above was your worst assumption, although you nee
On 3/12/2011 8:47 PM, Glenn Linderman wrote:
On 3/12/2011 2:09 PM, Terry Reedy wrote:
I believe that if the integer field were padded with leading blanks as
needed so that all are the same length, then no key would be needed.
Did you mean that "if the integer field were" converted to string an
On Mar 12, 2011, at 3:44 PM, Guido van Rossum wrote:
> I was just reminded that in Python 3, list.sort() and sorted() no
> longer support the cmp (comparator) function argument. The reason is
> that the key function argument is always better. But now I have a
> nagging doubt about this:
>
> I re
[steve@sylar ~]$ python2.7 -m timeit -s "L = [(1,2), (3,4), (0,5),
(9,100), (3,7), (2,8)]" "sorted(L, lambda (p,q),(r,s): cmp(p*s, q*r))"
1 loops, best of 3: 25.1 usec per loop
[steve@sylar ~]$ python2.7 -m timeit -s "L = [(1,2), (3,4), (0,5),
(9,100), (3,7), (2,8)]" -s "from fractions import
On 3/12/2011 8:28 PM, Steven D'Aprano wrote:
Fredrik Johansson wrote:
Consider sorting a list of pairs representing fractions. This can be
done easily in Python 2.x with the comparison function lambda
(p,q),(r,s): cmp(p*s, q*r). In Python 2.6, this is about 40 times
faster than using fractions.
On 3/12/2011 2:09 PM, Terry Reedy wrote:
I believe that if the integer field were padded with leading blanks as
needed so that all are the same length, then no key would be needed.
Did you mean that "if the integer field were" converted to string and
"padded with leading blanks..."?
Otherwi
Fredrik Johansson wrote:
Consider sorting a list of pairs representing fractions. This can be
done easily in Python 2.x with the comparison function lambda
(p,q),(r,s): cmp(p*s, q*r). In Python 2.6, this is about 40 times
faster than using fractions.Fraction as a key function.
[steve@sylar ~]
On 3/12/2011 5:09 PM, Reid Kleckner wrote:
On Sat, Mar 12, 2011 at 4:58 PM, Nick Coghlan wrote:
On Sat, Mar 12, 2011 at 4:50 PM, Reid Kleckner wrote:
They should be able to use a slotted cmp_to_key style class:
http://docs.python.org/howto/sorting.html
That will allocate 1 Python object with
On Sun, Mar 13, 2011 at 12:41 AM, "Martin v. Löwis" wrote:
> Am 12.03.11 18:00, schrieb Glenn Linderman:
>>
>> On 3/12/2011 1:55 PM, Fredrik Johansson wrote:
>>>
>>> Consider sorting a list of pairs representing fractions. This can be
>>> done easily in Python 2.x with the comparison function lam
Am 12.03.11 18:00, schrieb Glenn Linderman:
On 3/12/2011 1:55 PM, Fredrik Johansson wrote:
Consider sorting a list of pairs representing fractions. This can be
done easily in Python 2.x with the comparison function lambda
(p,q),(r,s): cmp(p*s, q*r). In Python 2.6, this is about 40 times
faster
On 3/12/2011 1:55 PM, Fredrik Johansson wrote:
Consider sorting a list of pairs representing fractions. This can be
done easily in Python 2.x with the comparison function lambda
(p,q),(r,s): cmp(p*s, q*r). In Python 2.6, this is about 40 times
faster than using fractions.Fraction as a key functio
But in Python 3 this solution is no longer available. How bad is that?
I'm not sure. But I'd like to at least get the issue out in the open.
Rather than reintroducing cmp=, I'd add a cached=True parameter.
If this is set to False, the key results wouldn't be put into a
list, but recreated every
On Sat, Mar 12, 2011 at 5:41 PM, "Martin v. Löwis" wrote:
> Why not? IIUC, the current key function creates three objects: the tuple,
> the short string, and the int. With the class
Yeah, I misread the example. Using cmp_to_key would indeed save quite
a lot of memory in this case.
Cheers,
Nick.
Guido van Rossum wrote:
> I was just reminded that in Python 3, list.sort() and sorted() no
> longer support the cmp (comparator) function argument. The reason is
> that the key function argument is always better. But now I have a
> nagging doubt about this:
>
> I recently advised a Googler who w
Am 12.03.11 16:58, schrieb Nick Coghlan:
On Sat, Mar 12, 2011 at 4:50 PM, Reid Kleckner wrote:
They should be able to use a slotted cmp_to_key style class:
http://docs.python.org/howto/sorting.html
That will allocate 1 Python object with no dict per key, but that
might not be good enough.
Tu
Can sort have an option (and/or try to figure it itself) to calculate
key for every comparison instead of caching them? This will have the
same memory requirements as with cmp, but doesn't require rewriting
code if you decide to trade speed for memory. Will this be much slower
than with cmp?
If go
On Sat, Mar 12, 2011 at 4:58 PM, Nick Coghlan wrote:
> On Sat, Mar 12, 2011 at 4:50 PM, Reid Kleckner
> wrote:
>> They should be able to use a slotted cmp_to_key style class:
>> http://docs.python.org/howto/sorting.html
>>
>> That will allocate 1 Python object with no dict per key, but that
>> m
On 3/12/2011 3:44 PM, Guido van Rossum wrote:
I was just reminded that in Python 3, list.sort() and sorted() no
longer support the cmp (comparator) function argument. The reason is
that the key function argument is always better. But now I have a
nagging doubt about this:
I recently advised a Go
On Sat, Mar 12, 2011 at 4:50 PM, Reid Kleckner wrote:
> They should be able to use a slotted cmp_to_key style class:
> http://docs.python.org/howto/sorting.html
>
> That will allocate 1 Python object with no dict per key, but that
> might not be good enough.
Tuples are already slotted, so that is
On Sat, Mar 12, 2011 at 9:44 PM, Guido van Rossum wrote:
> I was just reminded that in Python 3, list.sort() and sorted() no
> longer support the cmp (comparator) function argument. The reason is
> that the key function argument is always better. But now I have a
> nagging doubt about this:
>
> I
They should be able to use a slotted cmp_to_key style class:
http://docs.python.org/howto/sorting.html
That will allocate 1 Python object with no dict per key, but that
might not be good enough.
Reid
On Sat, Mar 12, 2011 at 3:44 PM, Guido van Rossum wrote:
> I was just reminded that in Python 3
27 matches
Mail list logo