Alternative to large "if-else" tree algorithm?
<p>brand new here, and fairly new to programming. I have written a program in Python that summarizes or "compresses" large UV-Vis absorbance data sets commonly encountered in chemistry and physics. I am trying to add the final touches to the program by making sections more "Pythonic". The following snippet is one such example.</p>

<pre><code>while j &lt; (N):
    j=j+1
    B=A[1+(10*j)+R][1:k] #Extraction expression.
    C=[float(i) for i in B] #Float conversion.
    D[0].append(C[0]),D[1].append(C[1]),D[2].append(C[2])
    if NC &gt;= 4:
        D[3].append(C[3])
        if NC &gt;= 5:
            D[4].append(C[4])
            if NC &gt;= 6:
                D[5].append(C[5])
                if NC &gt;= 7:
                    D[6].append(C[6])
                    if NC &gt;= 8:
                        D[7].append(C[7])
                        if NC &gt;= 9:
                            D[8].append(C[8])
                            if NC &gt;= 10:
                                D[9].append(C[9])
                                if NC &gt;= 11:
                                    D[10].append(C[10])
                                    if NC == 12:
                                        D[11].append(C[11])
</code></pre>

<p>C is a nested list. I am trying to append the index-specific elements contained within the lists inside C.</p>

<p>I.e. C = [[A1, B1, C1],[A2, B2, C2],[A3, B3, C3],...] 
-- > [A1, A2, A3,...An], [B1, B2, B3,...Bn],...</p>

<p>The problem is that if NC is equivalent to some index N, the indices of the nested lists are of the same index, and the append algorithm is different for each value of NC.</p>

<p>The above snippet works perfectly for my purposes, however as the program evolves, the length and duplicate code is not feasible long term.</p>

<p>Can someone point me in the right direction?</p>

<p>Cheers</p>