1、map 映射
l = [1, 2, 3, 4, 5] res = map(lambda x:x**2, l) print(list(res)) >>>[1, 4, 9, 16, 25]
注:
此时的res必须使用list(res)
否则只会返回一个对象
2、filter 过滤
l = [1, 2, 3, 4, 5] res = filter(lambda x:x>3, l) print(list(res)) >>>[4, 5]
3、reduce
from functools importreduce l = [1, 2, 3, 4, 5, 6] res = reduce(lambda x,y:x+y, l) print(res) # 1+2+3+4+5+6 >>>21
标签:map,Python,res,reduce,filter,list,print From: https://www.cnblogs.com/wellplayed/p/17762375.html