[Python-ideas] sum(...) limitation
Chris Kaynor
ckaynor at zindagigames.com
Wed Aug 13 20:05:52 CEST 2014
On Wed, Aug 13, 2014 at 10:46 AM, Steven D'Aprano <steve at pearwood.info>
wrote:
> That's another semantic change: sum() currently accepts iterators
> (although not *infinite* iterators). This revision has now broken tens
> of thousands of applications.
>
okay, how about:
def sum(items, start=0):
first = True
for item in items:
if first:
start = start + item
else:
start += item
return start
I believe that has the same effect as my other two, but only adds the
requirement that "value += item" behaves the same as "value = value + item".
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140813/f6cabd0c/attachment.html>
More information about the Python-ideas
mailing list