Commit acd22f91 authored by Neil Schemenauer's avatar Neil Schemenauer

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

usually preferred.
parent 7f2d4cb0
...@@ -1836,19 +1836,14 @@ cubes: ...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment