Python 特殊函数 lambda map filter

lam=lambda x:x+3
print(lam(2))
# print(help(map))
m=map(lambda x:x+3,range(10))
print(list(m))

lst1=[1,2,3,4,5]
lst2=[6,7,8,9,0]
lst3=[7,8,9,2,1]
xx=[x+y+z for x,y,z in zip(lst1,lst2,lst3)]
print(list(xx))
r=map(lambda x,y,z:x+y+z,lst1,lst2,lst3)
print(list(r))

n=range(-5,5)
f=filter(lambda x:x>0,n)
print(list(f))

l=[i for i in n if i>0]
print(list(l))

运行结果:

5
[3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
[14, 17, 20, 15, 6]
[14, 17, 20, 15, 6]
[1, 2, 3, 4]
[1, 2, 3, 4]

猜你喜欢

转载自blog.csdn.net/zhaoweiya/article/details/108891464