Python函数zip-map

>>> list(zip([1,3,5,7],[2,4,6,8]))
[(1, 2), (3, 4), (5, 6), (7, 8)]

把两个列表合成一个

 

也可以用map函数:

>>> list(map(lambda x,y:[x,y],[1,3,5,7],[2,4,6,8]))
[[1, 2], [3, 4], [5, 6], [7, 8]]

 

map函数:

map(F, multi-para)

F是个函数,后面可以带多个参数

>>> def format_name(s):
    s1=s[0:1].upper()+s[1:].lower()
    return s1

>>> list(map(format_name,['adam','help']))
['Adam', 'Help']

 

posted @ 2018-10-15 14:24  月亮上的石头  阅读(280)  评论(0)    收藏  举报