any faster alternative??

Posted by kaushik on Stack Overflow See other posts from Stack Overflow or by kaushik
Published on 2010-06-10T04:44:03Z Indexed on 2010/06/10 4:52 UTC
Read the original article Hit count: 257

Filed under:
|

I have to read a file from a particular line number and i know the line number say "n": i have been thinking of two choice:

1)for i in range(n) fname.readline() k=readline() print k

2)i=0 for line in fname: dictionary[i]=line i=i+1

but i want to know faster alternative as i might have to perform this on different files 20000 times. is there is any other better alternatives??

thanking u

© Stack Overflow or respective owner

any faster alternative??

Posted by kaushik on Stack Overflow See other posts from Stack Overflow or by kaushik
Published on 2010-06-10T05:42:58Z Indexed on 2010/06/10 5:52 UTC
Read the original article Hit count: 257

Filed under:
|
cost=0
for i in range(12):
    cost=cost+math.pow(float(float(q[i])-float(w[i])),2)
cost=(math.sqrt(cost))

Any faster alternative to this? i am need to improve my entire code so trying to improve each statements performance.

thanking u

© Stack Overflow or respective owner

Related posts about python

Related posts about Performance