為什么這里的reduce 函數需要加上第三個參數?
def calc_prod(lst):
??? def lazy_prod():
?????? def f(x,y):
?????????? return x*y
??????? return reduce(f,1st,1)
??????? #return reduce(f,1st)
??? return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
def calc_prod(lst):
??? def lazy_prod():
?????? def f(x,y):
?????????? return x*y
??????? return reduce(f,1st,1)
??????? #return reduce(f,1st)
??? return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
2015-04-07
舉報
2015-04-13
自己解讀下這句話,應該對你有幫助 If initial is present, it is placed before the items?of the sequence in the calculation, and serves as a default when the?sequence is empty.?