Name
map
Synopsis
map(func
,seq
,*seqs
)
Applies func
to every item of
seq
and returns a list of the results.
When map
is called with
n
+1
arguments, the
first one, func
, can be any callable
object that accepts n
arguments, or
None
. The remaining arguments to
map
must be iterable. When
func
is callable, map
repeatedly calls func
with
n
arguments (one corresponding item from
each iterable) and returns the list of results. Thus,
map(
func
,
seq
)
is the same as:
[func
(item
) foritem
inseq
]
When func
is None
,
map
returns a list of tuples, each with
n
items (one item from each iterable);
this is similar to zip
, covered in this section.
When the iterable objects have different lengths, however,
map
conceptually pads the shorter ones with
None
, while zip
conceptually
truncates the longer ones.
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.