reduce函数


###reduce_test 函数######################
# num_1 = [1,2,3,100]
# def reduce_test(func,array,init=None):
# if init is None:
# res = array.pop(0)
# else:
# res = init
# for num in array:
# res = func(res,num)
# return res
# ss = reduce_test(lambda x,y:x*y,num_1,2)
# print(ss)

###reduce 函数:
from functools import reduce

num_1 = [1,2,3,100]
res = reduce(lambda x,y:x+y,num_1,100)
print(res)
上一篇:python反序列化1(__reduce__)


下一篇:使用reduce实现随想转数组,数组转对象