[docs] sum( ) in generator bugged

Anselm Kiefner python at anselm.kiefner.de
Fri Nov 27 07:51:48 EST 2015


Hi,

I just found this bug:

Python 3.4.3+ (default, Oct 14 2015, 16:03:50)
[GCC 5.2.1 20151010] on linux

>>> L = [1,2,3]
>>> L_g = (x for x in L)
>>> a = [x*sum(L) for x in L]
>>> b = (x*sum(L_g) for x in L_g)
>>> print(a, list(b))
[6, 12, 18] [5]

whether b is a generator or not doesn't make a difference, it seems to
be a problem with sum() operating on L_g while L_g is consumed.
I stumbled over the problem first in ipython notebook running python
kernel 3.5.0, but couldn't find anything about it in the bugtracker.

Thanks,
Anselm


More information about the docs mailing list