<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Shafreeck Sea</b> <span dir="ltr"><<a href="mailto:renenglish@gmail.com">renenglish@gmail.com</a>></span><br>
Date: 2012/9/6<br>Subject: There is bug about the built-in function reduce in the document<br>To: <a href="mailto:docs@python.org">docs@python.org</a><br><br><br>Hi all:<br>I found a bug in the document about reduce :<br>
<a href="http://docs.python.org/library/functions.html#reduce" target="_blank">http://docs.python.org/library/functions.html#reduce</a><br><br>Here is the patch:<br>def reduce(function, iterable, initializer=None):<br>
    it = iter(iterable)<br>    if initializer is None:<br>        try:<br>            initializer = next(it)<br>        except StopIteration:<br>            raise TypeError('reduce() of empty sequence with no initial value')<br>

    accum_value = initializer<br><font color="#ff0000">-    for x in iterable:</font><div><font color="#ff0000">+   for x in it:</font><br>        accum_value = function(accum_value, x)<br>    return accum_value<div><br>
</div>
<div>It duplicated the first element of iterable </div></div><div><br></div><div>For example:</div><div><div>In [4]: reduce(lambda x,y:x+y, [1,2,3,4])</div><div>Out[4]: 10</div><div><br></div><div>In [5]: docreduce.reduce(lambda x,y:x+y ,[1,2,3,4])</div>

<div>Out[5]: 11</div></div><div><br></div><div>Sorry for my poor english !</div>
</div><br>