map

 1 #!/usr/bin/env python
 2 def f1(x):
 3     if x % 2 == 1:
 4         return x + 100
 5     else:
 6         return x
 7 ret = map(f1, [1,2,3,4,5])
 8 #相当于 ret = map(lambda x: x +100 if x % 2 == 1 else x,[1,2,3,4,5])
 9 for i in ret:
10     print(i)

结果:

C:Python35python3.exe F:/Python/2day/c2.py
101
2
103
4
105

Process finished with exit code 0
原文地址:https://www.cnblogs.com/shiluoliming/p/6382964.html