File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments