cpython (merge 3.2 -> default): Merge fix for Issue #12666 from 3.2

http://hg.python.org/cpython/rev/51af35bd46f7 changeset: 73821:51af35bd46f7 parent: 73818:3eb73f45a614 parent: 73820:0e2812b16f5f user: Jason R. Coombs <jaraco@jaraco.com> date: Sat Dec 03 08:59:53 2011 -0500 summary: Merge fix for Issue #12666 from 3.2 files: Doc/howto/pyporting.rst | 12 ++++++++++++ Doc/whatsnew/3.0.rst | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletions(-) diff --git a/Doc/howto/pyporting.rst b/Doc/howto/pyporting.rst --- a/Doc/howto/pyporting.rst +++ b/Doc/howto/pyporting.rst @@ -505,6 +505,18 @@ 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 --- a/Doc/whatsnew/3.0.rst +++ b/Doc/whatsnew/3.0.rst @@ -154,7 +154,9 @@ :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 @@ 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. -- Repository URL: http://hg.python.org/cpython
participants (1)
-
jason.coombs