python 函数 reduce、filter
## reduce >>> reduce(lambda x,y: x+y,[1,2,3,4,5]) 15 请看官仔细观察,是否能够看出是如何运算的呢?画一个图: 还记得map是怎么运算的吗?忘了?看代码: >>> list1 = [1,2,3,4,5,6,7,8,9] >>> list2 = [9,8,7,6,5,4,3,2,1] >>> map(lambda x,y: x+y, list1,list2) [10, 10, 10, 10, 10, 10, 10, 10, 10] 对比一下,就知道两个的区别了。原来map是上下运算,reduce是横着逐个元素进行运算。 权威的解释来自官网: reduce(function, iterable[, initializer]) Apply function of two arguments cumulatively to the items of iterable, from left to right, so as to reduce the iterable to a...