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

Stephen J. Turnbull stephen at xemacs.org
Sat Jul 6 03:53:45 CEST 2013


Terry Reedy writes:

 > In my experience of American English, normal people 'add' lists

Nitpick: That somehow doesn't sit right with me.  They "put lists
together" or "include one in another" (assign to slice, not list as
element of superior list).  Adding refers to elements: "add item to
list", although it's often applied iteratively (being synonymous to
"include in")..

I don't think it's appropriate to refer to any specific English usage
here.  Most native speakers, and especially programmers, have
flexibility in the direction of allowing the generalization of "+" to
strings to imply that "sum" also generalizes to strings, as the
iterated and associative application of "+".  They're even more
flexible than that: they intuitively understand that although "+" (and
perhaps even more so) usually imply "commutative" (as in the
convention in abstract algebra), when applied to strings and other
sequences this doesn't make sense (as of course it doesn't make sense
for infinite sequences in analysis).

I think that as far as consistency with intuition goes, it doesn't
matter which we choose: we really need to ask the ultimate authority
on "Pythonicity".  My own preference is based on "consenting adults":
if "sum(list_of_strings)" bothers you, don't use it.  But I don't
understand the ramifications of thoroughly implementing that in a
community where intuition splits as deeply as it evidently does here.

Steve


More information about the Python-ideas mailing list