[Solved] Python: How to store for loop result in a list? [duplicate]


Well the loop seems to be this one (at the end of the code):

for i,j in itertools.combinations([a,b,c],2):
    all_diffs=alldiffs(i,j)
    total=count_total(i,j)
    zero=count_zero(all_diffs)
    total=np.array(total)
    union=map(sub,total,zero)
    zero=np.array(zero).tolist()
    union=np.array(union).tolist()
    union=[list(x) for x in union]  
    sim=[[float(aaa) / bbb for (aaa, bbb) in itertools.izip(aa, bb)] \
        for (aa, bb) in itertools.izip(zero, union)]
    sim_comb=sum(sim,[])
    sum_of_sim=sum(sim_comb)
    number_sum=len(sim_comb)
    ave=sum_of_sim/number_sum
    one_ave=1-ave
    print one_ave

One possible solution would be to write:

output = []

for i,j in itertools.combinations([a,b,c],2):
    all_diffs=alldiffs(i,j)
    total=count_total(i,j)
    zero=count_zero(all_diffs)
    total=np.array(total)
    union=map(sub,total,zero)
    zero=np.array(zero).tolist()
    union=np.array(union).tolist()
    union=[list(x) for x in union]  
    sim=[[float(aaa) / bbb for (aaa, bbb) in itertools.izip(aa, bb)] \
        for (aa, bb) in itertools.izip(zero, union)]
    sim_comb=sum(sim,[])
    sum_of_sim=sum(sim_comb)
    number_sum=len(sim_comb)
    ave=sum_of_sim/number_sum
    one_ave=1-ave
    output += [one_ave]

print output

1

solved Python: How to store for loop result in a list? [duplicate]