I have an assignment to create a function loadResults where the number, time, name and surnames of the runners are stored, and returns a list of dictionaries with this information. The keys for the dictionary are: “number”, “name”, “surname”, “time”. So far I have:
def loadResults():
myFile = open("marathon.csv", "r")
number = []
for line in myFile:
info = line.split(',')
s = {}
s['number'] = info[0]
s['time'] = info[1]
s['firstname'] = info[2]
s['surname'] = info[3:]
number.append(s)
myFile.close
return number
however I then also have to write a function displayTime that receives the list of runners and the number of a runner and displays the name and the time. For which I have:
def displayTime(time,number,firstname):
for s in number:
if s['number'] == time:
print(s['name'])
runners = loadResults()
displayTime(number,'3070')
Unfortunately I am not getting anywhere with this any help would be greatly appreciated.