Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用函数的输出作为其他函数的输入_Python_Loops_Functional Programming - Fatal编程技术网

Python 使用函数的输出作为其他函数的输入

Python 使用函数的输出作为其他函数的输入,python,loops,functional-programming,Python,Loops,Functional Programming,我的软件是一组按顺序调用的函数: function1 -> function2 -> function3 .... 它们都收到相同的输入:一个名为options的字典 样本: def function1(options): # do something with options def function2(options): # do other thing with options def function3(options): # do other thi

我的软件是一组按顺序调用的函数:

function1 -> function2 -> function3 ....
它们都收到相同的输入:一个名为
options
的字典

样本:

def function1(options):
    # do something with options

def function2(options):
   # do other thing with options

def function3(options):
  # do other thing with options
有没有什么工具可以帮助我实现某种类型的功能

目前我正在使用循环:

flow = [function1,
 function2,
 function3]

options = {}
for phase in flow:
    phase(options)

谢谢。

这是你想要的吗


基于上面提到的信息,您当前的实现是完美的。为什么在为循环编写
时使用此选项更快、更高效、更清晰且可读?(哪个OP已经在使用)这对OP不起作用,因为所有这些函数都会原地改变arg,并且不返回任何值,这与Python中此类函数的常规情况相同。
def compose(*functions):
    return functools.reduce(lambda f, g: lambda x: f(g(x)), functions, lambda x: x)