def compose(*functions):
""" Returns the composition of functions"""
functions = reversed(functions)
def composition(*args, **kwargs):
func_iter = iter(functions)
ret = next(func_iter)(*args, **kwargs)
for f in func_iter:
ret = f(ret)
return ret
return composition
应该行得通。在
这是高阶函数
compose
的一个例子。到处躺着很方便现在可以将函数编写为
^{pr2}$等等
相关问题 更多 >
编程相关推荐