map和redue
按照我自己的理解:
map就是接收一個(gè)函數(shù),和一list,,,將該函數(shù)分別作用于list的每一個(gè)元素
list(map(f,[1,2,3,4,5,6])) = list(f(1),f(2),f(3),f(4),f(5),f(6))
而reduce就是相當(dāng)于一個(gè)遍歷迭代
reduce(f, [x1, x2, x3, x4]) = f(f(f(x1, x2), x3), x4)如果f為add
例:def add(x,y):
……return x+y
……
reduce(add,[1,2,3,4,5,6])
轉(zhuǎn)載于:https://www.cnblogs.com/chenxianghui/p/8335956.html
總結(jié)
- 上一篇: KVM 虚拟机 调整内存与CPU
- 下一篇: 动态ROM的刷新