Don't introduce map(None, ...) in the tutorial. In practice, zip() is

usually preferred.
This commit is contained in:
Neil Schemenauer 2003-08-14 22:57:46 +00:00
parent e98147a8e5
commit 90b182c16c

View file

@ -1836,19 +1836,14 @@ cubes:
More than one sequence may be passed; the function must then have as More than one sequence may be passed; the function must then have as
many arguments as there are sequences and is called with the many arguments as there are sequences and is called with the
corresponding item from each sequence (or \code{None} if some sequence corresponding item from each sequence (or \code{None} if some sequence
is shorter than another). If \code{None} is passed for the function, is shorter than another). For example:
a function returning its argument(s) is substituted.
Combining these two special cases, we see that
\samp{map(None, \var{list1}, \var{list2})} is a convenient way of
turning a pair of lists into a list of pairs. For example:
\begin{verbatim} \begin{verbatim}
>>> seq = range(8) >>> seq = range(8)
>>> def square(x): return x*x >>> def add(x, y): return x+y
... ...
>>> map(None, seq, map(square, seq)) >>> map(add, seq, seq)
[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25), (6, 36), (7, 49)] [0, 2, 4, 6, 8, 10, 12, 14]
\end{verbatim} \end{verbatim}
\samp{reduce(\var{func}, \var{sequence})} returns a single value \samp{reduce(\var{func}, \var{sequence})} returns a single value