I have a list of of string elements
marks = ["Bill, 50, 70, 90, 65, 81", "Jack, 80, 95, 100, 98, 72"]
I want to use a loop so that I can have a dictionary that looks like
dictionary= {'Bill': [50,70,90, 65, 81] , 'Jack': [80,95,100, 98, 72]}
The values should also be turned into floating values because I want to find the averages but I haven't gotten there yet.
This is what I have so far:
dictionary ={}
for items in marks:
c = items.split(', ')
for a in range(len(c)):
dictionary[c[0]] = c[a]
print(dictionary)
And it prints {'Bill': '81' , 'Jack': '72'}
The issue here is that I only get one value per key in my dictionary and it's the last value of the list and I understand it's because the dictionary[c[0]]= c[a] just replaces the previous one.
How do I go about so that the key can get multiple values without each previous value being changed in the loop?
Please let me know if loops are inefficient in doing this, but it is the only method I am comfortable doing at the moment.
Thanks!