[Python-ideas] Intermediate Summary: Fast sum() for non-numbers

Joshua Landau joshua at landau.ws
Mon Jul 15 23:56:10 CEST 2013


On 15 July 2013 22:36, David Mertz <mertz at gnosis.cx> wrote:
> On Mon, Jul 15, 2013 at 12:24 PM, Joshua Landau <joshua at landau.ws> wrote:
>>
>> But it is (sort of). I asked my brother (under 20, above 10, not sure
>> how much more I should say on a mailing list), who is about as
>> not-programmer-techy as any computer user could reasonably be. I asked
>> him to add two lists. He *concatenated them*¹.
>
>
> Here's my experimental contribution.

Thank you, this was interesting (although I don't particularly agree
with your interpretation).


> I found as a subject a "programming-naive" but well-educated subject in her
> 40s (a friend, no kidnapping of strangers off the street).  I asked
> something worded close to the following:
>
> "Can you sum these lists? An acceptable answer would be that the question
> does not make sense.  If it does make sense, what result do you get?"

Unfortunately, that's not, in my opinion, an accurate way to phrase
the question. If I were to say "can you mow these lawns" or "can you
catch these criminals" or "can you run these tests", I would be asking
for something along the lines of "map(verb, noun)". That's what she
dutifully did, as you note.

You should have asked "can you sum this list [note the singular noun]
of lists?" or somesuch. Because that's odd linguistically, you can say
instead "can you sum these lists together", although that's obviously
a bit of a rigged statement. You're free to think of a better
compromise.

Apologies for my fussiness.


> As a possible aid, I had a notepad placed nearby, in case some sort of
> copying operation was felt relevant (but I just made sure the notepad was on
> the table, I didn't say anything about whether it should or should not be
> used).

Copying your experimental choices, I actually think I rigged mine a
bit by giving a non-numeric values inside my lists, making more
imaginative choices much less likely. Kudos for the well-run
experiment, too (ignoring my issue of phrasing).


> Her answer was to write the additive sum of *each* slip of paper (list).
> I.e. three numbers: 18, 150, 600.
>
> In other words, she reads it as:
>
>   sum([[4,5,6,2,1], [6,12,13,19,100], [100,200,300]]) == [18, 150, 600]
>
> Well, this doesn't technically mean *anything* in Python since no 'start'
> value is given on the left.  But essentially her intuition is that it means:
>
>   map(sum, [[4,5,6,2,1], [6,12,13,19,100], [100,200,300]])
>
> Actually, that Python version is especially accurate, because what my
> informant actually said was "Do you want me to actually make the
> calculations?! That's what I'd do!" So much as with 3.x map, she didn't
> actually consume the iterator until needed.

:). This just proves that Python is a human.


More information about the Python-ideas mailing list