Python built-in function (--MAP)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.