📅  最后修改于: 2022-03-11 14:46:21.391000             🧑  作者: Mango
def reduce(function, iterable, initializer=None):
it = iter(iterable)
if initializer is None:
value = next(it)
else:
value = initializer
for element in it:
value = function(value, element)
return value