Replace map(None, *iterables) with zip(*iterables).

This commit is contained in:
Raymond Hettinger 2008-01-22 23:25:35 +00:00
parent 86def6cb2b
commit 1dfde1ddc0
9 changed files with 20 additions and 90 deletions

View file

@ -648,17 +648,7 @@ available. They are listed here in alphabetical order.
Return an iterator that applies *function* to every item of *iterable*,
yielding the results. If additional *iterable* arguments are passed,
*function* must take that many arguments and is applied to the items from all
iterables in parallel. If one iterable is shorter than another it is assumed
to be extended with ``None`` items. If *function* is ``None``, the identity
function is assumed; if there are multiple arguments, :func:`map` returns a
list consisting of tuples containing the corresponding items from all
iterables (a kind of transpose operation). The *iterable* arguments may be a
sequence or any iterable object; the result is always a list.
Note that for only one *iterable* argument, ``map(function, iterable)`` is
equivalent to the generator expression ``(function(item) for item in
iterable)`` if *function* is not ``None``.
iterables in parallel.
.. function:: max(iterable[, args...], *[, key])

View file

@ -204,21 +204,13 @@ loops that truncate the stream.
.. function:: imap(function, *iterables)
Make an iterator that computes the function using arguments from each of the
iterables. If *function* is set to ``None``, then :func:`imap` returns the
arguments as a tuple. Like :func:`map` but stops when the shortest iterable is
exhausted instead of filling in ``None`` for shorter iterables. The reason for
the difference is that infinite iterator arguments are typically an error for
:func:`map` (because the output is fully evaluated) but represent a common and
useful way of supplying arguments to :func:`imap`. Equivalent to::
iterables. Equivalent to::
def imap(function, *iterables):
iterables = map(iter, iterables)
iterables = [iter(it) for it in iterables)
while True:
args = [next(i) for i in iterables]
if function is None:
yield tuple(args)
else:
yield function(*args)
args = [next(it) for it in iterables]
yield function(*args)
.. function:: islice(iterable, [start,] stop [, step])