根据这个SO线程,
reduce
相当于fold。然而,在Haskell中,accum参数也会传递到fold中。在Python中,传递累加器的方法是什么呢?my_func(accum, list_elem):
if list_elem > 5:
return accum and True # or just accum
return accum and False # or just False
reduce(my_func, my_list)
在这里,我想将True
作为累加器传递。在Python中传递初始累加器值的方法是什么。
reduce
接受累加器作为第三个参数。 - 301_Moved_Permanently