How to get the needed varibales due to the condition?
<p>I have lists with values like this for example:</p>

<pre><code>values = [value_one, value_two, list_A[], list_B[], list_C[]]
</code></pre>

<p>... which are in a map (all these lists have the same structure as the example above, but with different values!):</p>

<pre><code>{
   key_one: valuesA,
   key_two: valuesB,
   key_three: valuesC,
   key_four: valuesD,
   key_five: valuesE,
   ...: ...,
   ...: ...
}
</code></pre>

<p>I also have this function:</p>

<pre><code>def calculate_process(map):
    for key, data in map.iteritems():
        value_one, value_two, list_A[], list_B[], list_C[] = data
        # do some calculation
        # ...
        # ...
</code></pre>

<p><strong>My problem:</strong></p>

<p>Due to my code, I want (depends on what condition it is) to get only certain lists. So the code should be more like this:</p>

<p><strong>Condition 1? Do:</strong></p>

<pre><code>def calculate_process(map):
        for key, data in map.iteritems():
            value_one, value_two, list_A[], list_B[] = data
            # do some calculation
            for value_first, value_second in zip(list_A[], list_B[])
                result = (value_one * value_two + value_first) * value_second
                # more other calculation
                # ...
</code></pre>

<p><strong>Condition 2? Do:</strong></p>

<pre><code>def calculate_process(map):
        for key, data in map.iteritems():
            value_one, value_two, list_B[], list_C[] = data
            # do some calculation
            for value_first, value_second in zip(list_B[], list_C[])
                result = (value_one * value_two + value_first) * value_second
                # more other calculation
                # ...
</code></pre>

<p><strong>Condition 3? do:</strong></p>

<pre><code>def calculate_process(map):
        for key, data in map.iteritems():
            value_one, value_two, list_A[], list_C[] = data
            # do some calculation
            for value_first, value_second in zip(list_A[], list_C[])
                result = (value_one * value_two + value_first) * value_second
                # more other calculation
                # ...
</code></pre>

<p>But I don't want to have three function, that does the same (because to have one function is way better), only what different is, is that I have to use different lists. I know, I could just write at the parameter something like "<strong>list_to_not_use=list_B</strong>", but I still have to do (here as an example) three "<strong>if</strong>" condition and could get so the certain lists, which I need.</p>

<p>But imagine, that this list structure..</p>

<pre><code>values = [value_one, value_two, list_A[], list_B[], list_C[]]
</code></pre>

<p>.. would be more like this...:</p>

<pre><code>values = [value_one, value_two, list_A[], list_B[], list_C[], list_D[], list_E[], ..., ...]
</code></pre>

<p>...yes, unknown endless list.</p>

<p>So the solution above (with the <strong>list_to_not_use</strong>) is at this situation not that good, because you would have to do more and more new "<strong>if</strong>" condition.</p>

<p><strong>My question:</strong></p>

<p>Is there a super good "impressive" solution, to solve this problem? Or is this such an easy question that you could solve it with ease, that I never have seen a programming code before?</p>

<p>I hope you understand my problem here and I hope you can help me there.</p>

<p>I also would appreciate some code examples :D</p>

<p>Thanks in advance!</p>

<p>If you can determine under different conditions which lists to be extracted before do_calculate, I suggest you use the positions of lists in the <code>data</code> tuple to extract them.</p>

<pre><code>def positions_of_list():
    # conditions
    return pos1, pos2

def calculate_process(map):
    for key, data in map.iteritems():
        pos1, pos2 = positions_of_list()
        v1 = data[0]
        v2 = data[1]
        l1 = data[pos1]
        l2 = data[pos2]
        # do calculate thereafter
</code></pre>

<p>function <code>positions_of_list</code> return positions of lists in <code>data</code> tuple.</p>

<p>Thanks</p>

python python-2.7