]> granicus.if.org Git - python/commitdiff
reduce(): Clarified what is returned in the case of a sequence 1 item long and
authorFred Drake <fdrake@acm.org>
Wed, 17 Jul 2002 13:55:33 +0000 (13:55 +0000)
committerFred Drake <fdrake@acm.org>
Wed, 17 Jul 2002 13:55:33 +0000 (13:55 +0000)
initial/default value.

Doc/lib/libfuncs.tex

index 5526dc53a7e5c2f8bfeb6f70a054859e4b5d0a4c..1aa59dc75c485fa6b5ef3ba2c409c342728c5159 100644 (file)
@@ -717,12 +717,12 @@ def my_import(name):
 \begin{funcdesc}{reduce}{function, sequence\optional{, initializer}}
   Apply \var{function} of two arguments cumulatively to the items of
   \var{sequence}, from left to right, so as to reduce the sequence to
-  a single value.  For example,
-  \code{reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])} calculates
-  \code{((((1+2)+3)+4)+5)}.
-  If the optional \var{initializer} is present, it is placed before
-  the items of the sequence in the calculation, and serves as a
-  default when the sequence is empty.
+  a single value.  For example, \code{reduce(lambda x, y: x+y, [1, 2,
+  3, 4, 5])} calculates \code{((((1+2)+3)+4)+5)}.  If the optional
+  \var{initializer} is present, it is placed before the items of the
+  sequence in the calculation, and serves as a default when the
+  sequence is empty.  If \var{initializer} is not given and
+  \var{sequence} contains only one item, the first item is returned.
 \end{funcdesc}
 
 \begin{funcdesc}{reload}{module}