[Patches] [ python-Patches-724936 ] new sum builtin
SourceForge.net
noreply@sourceforge.net
Mon, 21 Apr 2003 11:13:58 -0700
Patches item #724936, was opened at 2003-04-21 12:33
Message generated for change (Comment added) made by aleax
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=724936&group_id=5470
Category: Core (C code)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 7
Submitted By: Alex Martelli (aleax)
>Assigned to: Guido van Rossum (gvanrossum)
Summary: new sum builtin
Initial Comment:
as per discussion on Python-Dev. Note that
sum(manystrings), while still FAR faster than
reduce(operator.add, manystrings) and the equivalent loop,
is now about twice as slow as ''.join(manystrings) -- to
support the possibility that "manystrings" may be an
iterator, sum must retain the first item and
string-concatenate to it the ''.join of the others. I have not
mentioned this slight performance hit in the docs (just as
the far more severe performance trap with
reduce(operator.add, manystrings) is nowhere mentioned).
Also, I have not edited the tutorial. Please let me know if
you want more editing of such docs, I'll be quite glad to do
it, of course!
----------------------------------------------------------------------
>Comment By: Alex Martelli (aleax)
Date: 2003-04-21 20:13
Message:
Logged In: YES
user_id=60314
OK, changed again as requested. I have forbidden all
sequences (not just strings) as the value of start, since, as you
mention, performance problems would arise anyway. Yes, the
tutorial does cover reduce (specific example is reduce(add,...))
together with the other builtin higher-order functions.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2003-04-21 17:52
Message:
Logged In: YES
user_id=6380
I thought we would allow a second argument specifying the
starting point, defaulting to 0 (so w is never NULL). See
my pseudo code posted to python-dev. (Except if it used +=,
ignore that.)
Also, I would refrain from mentioning lists or tuples in the
docs, since those in fact have the same O(N**2) behavior as
strings. better use datetime.timedelta as the example.
What would you suggest to modify in the tutorial? Does it
even mention reduce()?
----------------------------------------------------------------------
Comment By: Alex Martelli (aleax)
Date: 2003-04-21 17:44
Message:
Logged In: YES
user_id=60314
modified as per GvR's pronouncement on python-dev: now
sum([]) returns 0, and it's specifically forbidden for the first item of
the argument to be a string (a TypeError is raised and the
message tells the user to use ''.join instead). Guido, please do let
me know if I should edit the tutorial as well, thanks!
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2003-04-21 14:21
Message:
Logged In: YES
user_id=6380
I have to rethink the idea that sum() should only apply to
numbers. The discussion brought up some new good points that
I need to ponder.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=724936&group_id=5470