1、最简单的:
-
>>> def add100(x):
-
... return x+100
-
...
-
>>> hh = [11,22,33]
-
>>> list(map(add100,hh)) #这是python 3 的用法,python 2中可以直接写map(add100,hh)
-
[111, 122, 133]
2、多参数。实现多个 list 纵向计算
-
>>> def abc(a, b, c):
-
... return a*10000 + b*100 + c
-
...
-
>>> list1 = [11,22,33]
-
>>> list2 = [44,55,66]
-
>>> list3 = [77,88,99]
-
>>> list(map(abc,list1,list2,list3))
-
[114477, 225588, 336699]
3、使用none函数,使多个 list 纵向合并行程新的 list
-
>>> list1 = [11,22,33]
-
>>> map(None,list1)
-
[11, 22, 33]
-
>>> list1 = [11,22,33]
-
>>> list2 = [44,55,66]
-
>>> list3 = [77,88,99]
-
>>> list(map(None,list1,list2,list3))
-
[(11, 44, 77), (22, 55, 88), (33, 66, 99)]
阅读(863) | 评论(0) | 转发(0) |