[Python-ideas] sum(...) limitation
David Mertz
mertz at gnosis.cx
Wed Aug 13 21:04:25 CEST 2014
This isn't the first time around in this discussion of (abusing) 'sum()'.
Actually, I discussed the last round in my keynote at PyCon UK in 2013.
In particular, I actually discussed there already how Chris' latest
version of 'sum()' breaks *existing* and *widespread* code.
My slides are at:
http://gnosis.cx/pycon-uk-2013/Keynote-Ideas.pdf
Look at slides 24-26. The TL;DR version: numpy arrays give different
meanings to __add__() and __iadd__(). Chris' version breaks every program
ever written that uses numpy.
On Wed, Aug 13, 2014 at 11:05 AM, Chris Kaynor <ckaynor at zindagigames.com>
wrote:
>
> 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
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
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/20140813/00721765/attachment-0001.html>
More information about the Python-ideas
mailing list