Feb-25-2019, 04:12 AM
I need help with this code I can't get it to work
# Read the input file.. and store in tuples with open("ALE.txt","r") as ins: # list to keep tuples array = [] for line in ins: # while storing, calulate win percentage also tok = line.rstrip('\n').split(',') t = (tok[0], tok[1], tok[2],"{0:.3f}".format(float(tok[1])/(float(tok[1]) + float(tok[2])))) # add this to list array.append(t) # sort the tuples, using 3rd column, win percentage array = sorted(array, key=lambda x: x[3], reverse=True) # open output file and write output = open('output.txt', 'w') for mytuple in array: output.write(",".join(mytuple) + "\n") output.close()