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

David Mertz mertz at gnosis.cx
Mon Jul 15 23:36:17 CEST 2013


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.  I cut and drew on three pieces of
paper similar to the below ASCII art:

______________________
|  4   5   6   2   1

      ______________________
      |  6   12   13   19   100

______________________
|  100   200   300

In particular, I put small integers on them, but for generality made the
numbers sometimes out of natural sort order.  I also made the lists of
different lengths so that elementwise addition would pose a problem (a
subject *could* decide to fill in the additive identity zero for the
"missing" elements if she wanted to, but this would have to be a
decision).  I also placed the papers deliberately so that the left edges
were not aligned (as pictured) so the notion of columns would not be forced
on an informant (but not prohibited either).

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?"

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).

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.


¹ Sort of. He combined them as you would sorted Counters, where

> duplicate items were doubled-up on, but otherwise order was preserved.
> I think that is reasonably close.
>

-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130715/d05f5635/attachment.html>


More information about the Python-ideas mailing list