Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5a85eb5d
Commit
5a85eb5d
authored
Dec 03, 2011
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Plain Diff
Merge fix for Issue #12666 from 3.2
parents
9264faed
e6f778cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
1 deletion
+21
-1
Doc/howto/pyporting.rst
Doc/howto/pyporting.rst
+12
-0
Doc/whatsnew/3.0.rst
Doc/whatsnew/3.0.rst
+9
-1
No files found.
Doc/howto/pyporting.rst
View file @
5a85eb5d
...
...
@@ -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
-------------------------
...
...
Doc/whatsnew/3.0.rst
View file @
5a85eb5d
...
...
@@ -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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment