English documents:
-
map ( function , iterable , ...
-
-
Return An iterator, applies function to Every item of iterable , yielding the results. If additional iterable arguments is passed, function must take that many arguments and is applied To the items from all iterables in parallel. With multiple iterables, the iterator stops when the shortest iterable is exhausted. For cases where the function inputs is already arranged into argument tuples, see
itertools.starmap () .
-
-
-
-
Description:
-
1. The function accepts a function type parameter, one or more iterated object parameters, and returns an iterative , each element in this iterator is the result of a function parameter instance calling an object that can iterate.
-
>>> a = Map (ord,'abcd')>>> a<map object at 0x03994e50>>>> List (a) [97, 98, 99, 100]
2. When multiple iterations of an object are passed in, the parameters of the function must provide sufficient parameters to ensure that the values of the same index of each iteration object pass correctly to the function.
>>> a = map (ord,'ABCD')>>>list (a) [97, 98, 99, 100]>>> a = map (ord,'ABCD','EFG')#two iterations are passed in, so the incoming function must be able to receive 2 parameters, and Ord cannot receive 2 parameters, so an error>>>List (a) Traceback (most recent call last): File"<pyshell#22>", Line 1,inch<module>List (a) Typeerror:ord () takes exactly one argument (2given)>>>defF (A, B):returnA +b>>> a = map (f,'ABCD','EFG')#The f function can accept 2 parameters>>>list (a) ['AE','BF','CG']
3. When multiple iterators are passed in, and their element lengths are inconsistent, the resulting iterator is only to the shortest length.
def F (A, B ): return A + b>>> a = map (f,'abcd','EFG') # Select a minimum length of 3>>> List (a) ['ae' 'BF'CG']
4. The map function is a typical example of functional programming.
Python built-in function (--MAP)