mirror of
https://github.com/python/cpython.git
synced 2025-11-19 10:46:17 +00:00
Issue #12666: Clarifying changes in map for Python 3
This commit is contained in:
parent
9aa20affb6
commit
df9a5f5ecf
1 changed files with 9 additions and 1 deletions
|
|
@ -154,7 +154,9 @@ Some well-known APIs no longer return lists:
|
||||||
:meth:`dict.itervalues` methods are no longer supported.
|
:meth:`dict.itervalues` methods are no longer supported.
|
||||||
|
|
||||||
* :func:`map` and :func:`filter` return iterators. If you really need
|
* :func:`map` and :func:`filter` return iterators. If you really need
|
||||||
a list, a quick fix is e.g. ``list(map(...))``, but a better fix is
|
a list and the input sequences are all of equal length, a quick
|
||||||
|
fix is to wrap :func:`map` in :func:`list`, e.g. ``list(map(...))``,
|
||||||
|
but a better fix is
|
||||||
often to use a list comprehension (especially when the original code
|
often to use a list comprehension (especially when the original code
|
||||||
uses :keyword:`lambda`), or rewriting the code so it doesn't need a
|
uses :keyword:`lambda`), or rewriting the code so it doesn't need a
|
||||||
list at all. Particularly tricky is :func:`map` invoked for the
|
list at all. Particularly tricky is :func:`map` invoked for the
|
||||||
|
|
@ -162,6 +164,12 @@ Some well-known APIs no longer return lists:
|
||||||
regular :keyword:`for` loop (since creating a list would just be
|
regular :keyword:`for` loop (since creating a list would just be
|
||||||
wasteful).
|
wasteful).
|
||||||
|
|
||||||
|
If the input sequences are not of equal length, :func:`map` will
|
||||||
|
stop at the termination of the shortest of the sequences. For full
|
||||||
|
compatibility with `map` from Python 2.x, also wrap the sequences in
|
||||||
|
:func:`itertools.zip_longest`, e.g. ``map(func, *sequences)`` becomes
|
||||||
|
``list(map(func, itertools.zip_longest(*sequences)))``.
|
||||||
|
|
||||||
* :func:`range` now behaves like :func:`xrange` used to behave, except
|
* :func:`range` now behaves like :func:`xrange` used to behave, except
|
||||||
it works with values of arbitrary size. The latter no longer
|
it works with values of arbitrary size. The latter no longer
|
||||||
exists.
|
exists.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue