Accelerating For Loop

Chris Rebert clp2 at
Wed Feb 23 08:37:03 CET 2011

2011/2/22 Şansal Birbaş <sansal.birbas at>:
> Hi All,
> I needed to find the cheapest combination among given data and I developed
> an algorithm for this task. It works correctly. But it takes much time
> (nearly 2 minutes) for second function to find the result while it is just
> one second for the first function. How can I improve the calculation speed?
>    temp=[]
>    temp.append(i)
>    temp.append(j)
>    temp.append(k)
>    temp.append(m)
>    temp.append(r)
>    fiyat=i*X[4]+j*Y[4]+k*Z[4]+m*T[4]+r*W[4]
>    temp.append(fiyat)
>    combinations.append(temp)

More efficiently and concisely written as:
fiyat = i*X[4]+j*Y[4]+k*Z[4]+m*T[4]+r*W[4]
combo = [i, j, k, m, r, fiyat]


More information about the Python-list mailing list