Message242240
On 29 April 2015 at 19:42, Sergey B Kirpichev <report@bugs.python.org> wrote:
>> It's a common computer science technique
>
> Could you provide any language that avoid this optimization?
>
> Here is Perl 5:
> http://perl5.git.perl.org/perl.git/blob/HEAD:/pp_sort.c#l367
>
> (third example)
But that's a sort without a key. In Perl you do a key sort via:
@sorted = map { $_->[0] }
sort { $a->[1] <=> $b->[1] } # use numeric comparison
map { [$_, length($_)] } # calculate the length of the string
@unsorted;
(From http://en.wikipedia.org/wiki/Schwartzian_transform). That
computes the keys first, and would compute the key for a list of
length 1, just like Python does. It's just that Python bundles that
whole construct into the "key=" argument.
But it's your choice - if this is a big enough deal to put you off
Python, I guess no-one will be able to stop you. The fact of the
matter is that what Python does is documented behaviour, and the
benefit (small) isn't worth the cost of making a change (which would
only be in Python 3.5 and later anyway, as it's a backward
incompatible change, not a bug fix). |
|
Date |
User |
Action |
Args |
2015-04-29 18:51:21 | paul.moore | set | recipients:
+ paul.moore, tim.peters, rhettinger, mark.dickinson, benjamin.peterson, r.david.murray, matrixise, Sergey.Kirpichev |
2015-04-29 18:51:21 | paul.moore | link | issue24075 messages |
2015-04-29 18:51:21 | paul.moore | create | |
|