python - Understanding the map function -
map(function, iterable, ...) apply function every item of iterable , return list of results. if additional iterable arguments passed, function must take many arguments , applied items iterables in parallel.
if 1 iterable shorter assumed extended none items.
if function none, identity function assumed; if there multiple arguments, map() returns list consisting of tuples containing corresponding items iterables (a kind of transpose operation).
the iterable arguments may sequence or iterable object; result list.
what role play in making cartesian product?
content = map(tuple, array) what effect putting tuple anywhere in there have? noticed without map function output abc , it, it's a, b, c.
i want understand function. reference definitions hard understand. fancy fluff.
map isn't particularly pythonic. recommend using list comprehensions instead:
map(f, iterable) is equivalent to:
[f(x) x in iterable] map on own can't cartesian product, because length of output list same input list. can trivially cartesian product list comprehension though:
[(a, b) in iterable_a b in iterable_b] the syntax little confusing -- that's equivalent to:
result = [] in iterable_a: b in iterable_b: result.append((a, b))
Comments
Post a Comment