Access Functions via Dictionary
<p>I have a function like this:</p>

<pre><code>def abc(a,b):
    return a+b
</code></pre>

<p>And I want to assign it to a dictionary like this:</p>

<pre><code>functions = {'abc': abc(a,b)}
</code></pre>

<p>The trouble is, when assigning it to the dictionary, since the arguments are not yet defined, I get the error: </p>

<pre><code>NameError: name 'a' is not defined
</code></pre>

<p>I would do the obvious thing and define the arguments ahead of time but I need to define them in a loop (and then call the function based on locating it in a list) like this:</p>

<pre><code>functions_to_call = ['abc']
for f in functions_to_call:
    a=3
    b=4
#This is supposed to locate and run the function from the dictionary if it is in the list of functions.
    if f in functions:
       functions[f] 
</code></pre>

<p>You assign a reference to the function <strong>without</strong> any arguments, and then supply them when calling it:</p>

<pre><code>functions = {'abc':abc} # Assignment: no arguments!
functions_to_call = ['abc']
for f in functions_to_call:
    a=3
    b=4
    if f in functions:
            functions[f](a, b) # calling with arguments
</code></pre>

python list function python-3.x dictionary