码迷,mamicode.com
首页 > 其他好文 > 详细

map

时间:2016-12-02 18:58:50      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:rom   stop   iterator   迭代   short   highlight   arguments   int   com   

class map(object):
    """
    map(func, *iterables) --> map object
    
    Make an iterator that computes the function using arguments from  
    each of the iterables.  Stops when the shortest iterable is exhausted.
    创建一个迭代器,使用参数(func)计算函数每个迭代(from *iterables)。 当最短迭代次数耗尽时停止
    """

map(第一个参数,第二个参数)

第一个参数接收一个函数名,第二个参数接收一个可迭代对象

举个栗子:

li = [1, 2, 3, 4, 5, 6]
s = map(str, li)
print(s)
print(list(s))
<map object at 0x00000151D9A2D5F8>
[‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘]

 

li = [1, 2, 3, 4, 5, 6]
def add_one(x):
    return x +1
a = list(map(add_one,  li))
print(a)
[2, 3, 4, 5, 6, 7]

  

map

标签:rom   stop   iterator   迭代   short   highlight   arguments   int   com   

原文地址:http://www.cnblogs.com/lcgsmile/p/6126703.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!