标签:init port lam col pytho none span bsp style
from functools import reduce num_1 = [1, 2, 3, 4, 5] #加法 def reduce_test(array): res = 0 for num in num_1: res += num return res #乘法 def reduce_test(func, array, init=None): if init is None: res = array.pop(0) else: res = init for num in num_1: res *= func(res, num) return res print(reduce_test(lambda x, y: x*y, num_1) # reduce函数 res = reduce(lambda x, y: x+y, num_1, 1) print(res)
标签:init port lam col pytho none span bsp style
原文地址:https://www.cnblogs.com/majianyu/p/10087529.html