from operator import itemgetter
file = open("testdata.txt","r")
filein = []
for row in file:
filein.append(row.strip("\n"))
results= []
for item in filein:
results.append(item.split(","))
counter=0
for item in results:
itemlength = len(item)
for i in range(1, itemlength):
item[i] = int(item[i])
item.append(max(results[counter][1:4]))
item.append((sum(results[counter][1:4]))/3)
counter=counter+1
results.sort()
print("\n")
print(sorted(results,key=itemgetter(5),reverse=True))
[['DF', 8, 6, 8, 8, 7.333333333333333], ['ED', 10, 4, 6, 10, 6.666666666666667], ['TH', 9, 4, 7, 9, 6.666666666666667], ['EK', 9, 4, 5, 9, 6.0]]
I have two questions. The first one is how can I print the first value (initials) with the 5th value [4], which is the highest score, in a new list? My second question how can I get the average score[5] of the three scores to 2 decimal places?
This task is for my assessment, I hope that you could help me out! Thank you