[Python] reduce () function

Python reduce () function
reduce () function parameter sequence elements have accumulated.
All data is a function of data set (a list, tuple, etc.) are the following: (two parameters) of the first set of first and second elements with the function operates in the function passed to reduce, obtained results further data to the third function operation function, to obtain a final result.

Encoding #:. 8 UTF- 
DEF the Add (X, Y): adding two numbers # 
    return X + Y 
Print the reduce (the Add, [1,2,3,4,5])  

Similar php of array_reduce

<?php
function add($x,$y){

        return $x+$y;
}
$r=array_reduce([1,2,3,4,5],"add");
var_dump($r);

 

Guess you like

Origin www.cnblogs.com/taoshihan/p/12331909.html