Nothing changed, Mr. Chris -----Original Message----- From: ch...@rebertia.com [mailto:ch...@rebertia.com] On Behalf Of Chris Rebert Sent: Wednesday, February 23, 2011 9:37 AM To: Şansal Birbaş Cc: python-list@python.org Subject: Re: Accelerating For Loop
2011/2/22 Şansal Birbaş <sansal.bir...@alarko-carrier.com.tr>: > 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? <snip> > 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] combinations.append(combo) Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list