What is the best way to store a list of functions?
<p>I need to store a large numbers of functions rules in Python (around 100000 ), to be used after....</p>

<pre><code>def rule1(x,y) :...
def rule2(x,y): ...
</code></pre>

<p>What is the best way to store, manage those function rules instance into Python structure ? </p>

<p>What about using Numpy dtype=np.object array ?
(list are bad when they become too large...)</p>

<p>Main goal is to access in the fastest and minimum memory footprint when storing in memory.</p>

<p>Thanks</p>

<p>When you use those rules, you're going to have to reference them <em>somehow</em>. If your example is a hint of the naming convention, then go with a list. Calling them in sequence would be easy via <code>map</code> or in a loop.</p>

<pre><code>rules = [rule1, rule2, ...]
for fn in rules:
    fn(arg1, arg2)  # this calls rule1 and rule2 with args (as an example)
</code></pre>

<p>If you may also reference them by name, then use a dict, like:</p>

<pre><code>rules = {'rule1': rule1, 'rule2': rule2, ...}
something = rules['rule5'](arg1, arg2)
# or
for rule in rules:  # iterates over the dict's keys
    rules[rule](arg1, arg2)
</code></pre>

python