summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2011-12-03 13:59:53 (GMT)
committerJason R. Coombs <jaraco@jaraco.com>2011-12-03 13:59:53 (GMT)
commitc9b644eac28614ae74afb52432ad71d7077e8add (patch)
tree99d52481615de7e2c2c956f9a8b7f0fc1f256580
parent506b361a977fcb258a25cadabbdf85ce86728ba7 (diff)
parenta90e364ea5c301e76e67e23e2162f4fa8066a6f3 (diff)
downloadcpython-c9b644eac28614ae74afb52432ad71d7077e8add.zip
cpython-c9b644eac28614ae74afb52432ad71d7077e8add.tar.gz
cpython-c9b644eac28614ae74afb52432ad71d7077e8add.tar.bz2
Merge fix for Issue #12666 from 3.2
-rw-r--r--Doc/howto/pyporting.rst12
-rw-r--r--Doc/whatsnew/3.0.rst10
2 files changed, 21 insertions, 1 deletions
diff --git a/Doc/howto/pyporting.rst b/Doc/howto/pyporting.rst
index 309f3f7..df0d299 100644
--- a/Doc/howto/pyporting.rst
+++ b/Doc/howto/pyporting.rst
@@ -505,6 +505,18 @@ Otherwise it might very well be worth your time and effort to port your tests
to :mod:`unittest`.
+Update `map` for imbalanced input sequences
+'''''''''''''''''''''''''''''''''''''''''''
+
+With Python 2, `map` would pad input sequences of unequal length with
+`None` values, returning a sequence as long as the longest input sequence.
+
+With Python 3, if the input sequences to `map` are of unequal length, `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)))``.
+
Eliminate ``-3`` Warnings
-------------------------
diff --git a/Doc/whatsnew/3.0.rst b/Doc/whatsnew/3.0.rst
index 852f811..523b34e 100644
--- a/Doc/whatsnew/3.0.rst
+++ b/Doc/whatsnew/3.0.rst
@@ -154,7 +154,9 @@ Some well-known APIs no longer return lists:
:meth:`dict.itervalues` methods are no longer supported.
* :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
uses :keyword:`lambda`), or rewriting the code so it doesn't need a
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
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
it works with values of arbitrary size. The latter no longer
exists.