Off topic:Why Is This For Statement Appending Twice? Python
0
0
Entering edit mode
12.4 years ago
alpha_sum = [2396, 780, 2022, 596]
alpha_b_sum = [2206, 828, 1962, 597]
results_alpha = [[145, 142, 142, 111, 121, 151, 111, 113, 121, 106, 67, 151, 57, 111, 106, 101, 111, 98, 142, 106, 83], [142, 106, 83, 69, 145, 121, 114], [69, 145, 121, 114, 57, 121, 111, 121, 151, 77, 121, 77, 101, 113, 142, 77, 113, 108, 83], [113, 108, 83, 77, 114, 101], [57, 106, 98, 101, 101, 108, 108, 77, 114, 106, 142, 57, 113, 67], [101, 121, 77, 121, 57, 142, 142, 114, 121]]
values_alpha= [145, 142, 142, 111, 121, 151, 111, 113, 121, 106, 67, 151, 57, 111, 106, 101, 111, 98, 142, 106, 83, 69, 145, 121, 114, 57, 121, 111, 121, 151, 77, 121, 77, 101, 113, 142, 77, 113, 108, 83, 77, 114, 101, 69, 151, 67, 57, 106, 98, 101, 101, 108, 108, 77, 114, 106, 142, 57, 113, 67, 77, 101, 121, 77, 121, 57, 142, 142, 114, 121]



for alpha, alpha_b in zip(alpha_sum,  alpha_b_sum):
    for i in range(len(values_alpha)):
        if alpha > alpha_b:

            for element in results_alpha:

                length = len(element)
                if values_alpha[i:i+length] == element:

                    export.append('Alpha'+'\t'+'[%d, %d]' % (i, i+length-1)+'\n') 
                    #print '[%d,%d]' % (i, i+length-1)+'\n'

                else:
                    pass

print export
['Alpha\t[0, 20]\n', 'Alpha\t[18, 24]\n', 'Alpha\t[21, 39]\n', 'Alpha\t[37, 42]\n', 'Alpha\t[46, 59]\n', 'Alpha\t[61, 69]\n', 
 'Alpha\t[0, 20]\n', 'Alpha\t[18, 24]\n', 'Alpha\t[21, 39]\n', 'Alpha\t[37, 42]\n', 'Alpha\t[46, 59]\n', 'Alpha\t[61, 69]\n']

Why is it appending the data twice???

Whats going on here is a list of numbers -> values_alpha

and within that list there are certain portions which were appended to -> results_alpha

so resultsalpha has portions of valuesalpha

i'm trying to check if each element in alphasum > alphabsum and if it is, add the positions that particular sequence occurred (element in resultsalpha) within the original sequence (values_alpha) . if not then just skip it, hence the pass command

python off • 3.0k views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 3332 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6