How to pass list of function and all its arguments to be executed in another function in python?
<p>I have a list of functions and its arguments like this:</p>

<pre><code>(func1, *arg1), (func2, *arg2),...
</code></pre>

<p>I want to pass them into another function to execute them like this:</p>

<pre><code>for func, arg* in (list of funcs, args):
   func(arg*)
</code></pre>

<p>How to do it in python? I have tried several but it doesn't like unpacking and *arg at the same time.</p>

<p>You can use the <a href="https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists" rel="nofollow">*-operator to unpack the arguments out of the tuple</a>.</p>

<p>For example, suppose the format of items in your invocation list is <code>(function,arg1,arg2,...)</code>. In other words, <code>item[0]</code> is your function, while <code>item[1:]</code> are the arguments the should be given to the function.</p>

<pre><code>def f1(x1):
    print("f1 {0}".format(x1))

def f2(x1,x2):
    print("f2 {0} {1}".format(x1,x2))

for data in ((f1,5),(f2,3,4)):
    data[0](*data[1:])
# output:
#   f1 5
#   f2 3 4
</code></pre>

python