[Python-ideas] Intermediate Summary: Fast sum() for non-numbers
Joshua Landau
joshua at landau.ws
Fri Jul 19 11:05:51 CEST 2013
On 19 July 2013 05:07, Steven D'Aprano <steve at pearwood.info> wrote:
> On 19/07/13 04:42, David Mertz wrote:
>>
>> OK... I have an update to my experiment. I asked by email another friend
>> of
>> mine (also middle-aged adult, well-educated, a doctorate in humanities
>> FWIW
>> [like me]), this one has had an introductory exposure to programming, and
>> in Python specifically, but just one semester-long intro course (the
>> wonderful edX MIT Intro to CS, a few months ago).
>
>
> While we're swapping anecdotes instead of doing proper UI testing *grin* (or
> perhaps API testing would be a better term), I asked two of my programmers
> at work what they would do if they had a list of lists and needed to
> concatenate them into a single list. Both are moderately familiar with
> Python, although one (call him R) is more familiar with Ruby and
> Objective-C.
Thank you both, again.
One conclusion I think it's safe to take from this is that it is *not*
a clear-cut issue as many people, myself included, had assumed. I
think it's fair to say that people claiming (Stefan Behnel in this
case, because it was the first quotation I found):
> IMHO, the reason why sum() supports other input types than numbers is that
> in Python 2, at the time when it was implemented, there was no clear
> definition of a "number"
or similar have missed this point. My claims that it obviously does
make sense (although it's not necessarily a good idea) was equally
wrong in this regard.
Also,
> Neither thought that they would gain much if sum() was sped up, M
> because he wouldn't use it to join lists regardless of speed, and R
> because he thought it would be unlikely that he'd ever be in a position
> of needing to join sufficient numbers of lists to really make a difference,
> but if he was, refactoring was such a trivial exercise that he didn't care
> one way or another.
I agree in large with R, except that I'd never opt for sum() over
chain.from_iterable().
More information about the Python-ideas
mailing list