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

Stephen J. Turnbull stephen at xemacs.org
Fri Jul 12 05:52:12 CEST 2013


Sergey writes:

 > Which effectively means do nothing and agree that slow sum is the best
 > for python.

Sum is not slow for numbers, which many posters believe is the only
plausible usage, despite the accident that it can be used for other
types.

 > Despite we CAN make it faster.

Faster is not necessarily better.  Several posters have claimed that
"sum(list_of_lists)" is unreadable (for them).  While Python is a
"consenting adults" language (so "if you don't like it, don't use it"
is a plausible argument), Python aspires to "universal" readability.
So plausibly "sum(list_of_lists)" is a bad thing in itself.  If
there's another "obvious way to do it" (here, itertools.chain which is
both efficient computationally and lazy), then making sum() better
only encourages use.  There are a couple of similar optimizations that
Guido himself admits he regrets.

Consider "sum(sum(list_of_lists_of_numbers))".  For me, that's a WTF.
I'd much rather "sum(chain(list_of_lists_of_numbers))".

I don't ask you to agree, let alone expect you to do so.  I would hope
you can offer the same courtesy for those who disagree with you.  Here
I am only trying to explain why they might disagree with you, and why
it may be difficult to change their minds.

 > For all cases, or for most of them, but we could at least start
 > discussing options, instead of repeating excuses.

"Do nothing" is an option, and it's the one preferred by most posters
at this point.

If you don't like that, write a PEP, present it here, and then on
python-dev, and get it approved.  As has been pointed out, a PEP is
needed, and the candidates for PEP czar probably are no longer
listening, and none of them have argued against, so you do have a
chance to convince that way.  But as also has been pointed out, you
haven't presented a new argument for several days, and your old ones
haven't convinced.  You need to either try something new, or get a new
audience (by writing the PEP).  Nobody else is going to do it for you.

BTW, "make the TOOWTDI for sequences a built-in" is a new option
recently proposed and now being discussed.  (Ie, the subthread
discussing that for "itertools.chain.from_iterable".)  I kinda like
"ichain" for the name, and I like that proposal.

Regards,


More information about the Python-ideas mailing list