Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df9a5f5

Browse files
committed
Issue #12666: Clarifying changes in map for Python 3
1 parent 9aa20af commit df9a5f5

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

Doc/whatsnew/3.0.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,22 @@ Some well-known APIs no longer return lists:
154154
:meth:`dict.itervalues` methods are no longer supported.
155155

156156
* :func:`map` and :func:`filter` return iterators. If you really need
157-
a list, a quick fix is e.g. ``list(map(...))``, but a better fix is
157+
a list and the input sequences are all of equal length, a quick
158+
fix is to wrap :func:`map` in :func:`list`, e.g. ``list(map(...))``,
159+
but a better fix is
158160
often to use a list comprehension (especially when the original code
159161
uses :keyword:`lambda`), or rewriting the code so it doesn't need a
160162
list at all. Particularly tricky is :func:`map` invoked for the
161163
side effects of the function; the correct transformation is to use a
162164
regular :keyword:`for` loop (since creating a list would just be
163165
wasteful).
164166

167+
If the input sequences are not of equal length, :func:`map` will
168+
stop at the termination of the shortest of the sequences. For full
169+
compatibility with `map` from Python 2.x, also wrap the sequences in
170+
:func:`itertools.zip_longest`, e.g. ``map(func, *sequences)`` becomes
171+
``list(map(func, itertools.zip_longest(*sequences)))``.
172+
165173
* :func:`range` now behaves like :func:`xrange` used to behave, except
166174
it works with values of arbitrary size. The latter no longer
167175
exists.

0 commit comments

Comments
 (0)