1

Could you please help me speed up this code? It takes a very long time to run because of how big the input file is, thank you to anyone who helps out.

racers = [int(file[0].split()[0]) / float(x) for x in file[0].split()[1::]]
print("hi")
def av(race):
    race = race.split()
    j = 0
    while j != len([float(race[0]) / float(x) for x in race[1::]]):
        racers[j] = [float(race[0]) / float(x) for x in race[1::]][j] + racers[j]
        j += 1
for i in range(1, len(file)):
    av(file[i])
a = min(racers)
del(racers[racers.index(min(racers))])
b = min(racers)
c = b-a
h = int(c)
c-=h

m = int(c * 60)
c-=m/60
s = round(c * 60 * 60)
print(str(h) + "h" + str(m) + "m" + str(s) + "s")
  • this question might be helpful http://stackoverflow.com/questions/15096269/the-fastest-way-to-read-input-in-python for taking faster input from file in python – warl0ck Apr 03 '17 at 05:59
  • why not just use `pandas.read_csv` ? It has an excellent, fast, versatile parser. The conversion of the time to hours and minutes can be made easier with `pandas.to_timedelta`. For a more specific answer, and excerpt of the file would be useful – Maarten Fabré Apr 03 '17 at 07:27

0 Answers0