restriction on sum: intentional bug?

Mark Dickinson dickinsm at gmail.com
Sat Oct 17 17:00:36 EDT 2009


On Oct 17, 9:49 pm, a... at pythoncraft.com (Aahz) wrote:
> Ahhh, I vaguely remember there being some discussion of this when sum()
> was introduced -- I think that using InPlaceAdd would have caused bad
> behavior when the initial list was referred to by multiple names.

Ah yes.  Good point.  With my one-line modification, I get:

Python 2.7a0 (trunk:75468M, Oct 17 2009, 21:57:02)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> acc = []
>>> sum(([i] for i in range(10)), acc)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> acc
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

There should probably be a test for this somewhere, to make
sure that no-one else is tempted to make this change.

--
Mark



More information about the Python-list mailing list