EDIT:
This is not a duplicate of finding average values of a list because this list is a value that is assigned to a key.
Had to clear that up for those who didn't get it.
I have a dictionary where every key has a list/multiple of values:
'Jimin ': ['0', '0', '0', '0', '0', '0'], 'Jin': ['1', '0'],
I want to print out the average of the values for every key e.g:
'Jimin ':[0], 'Jin': [0.5],
I have already tried:
avgDict = {}
for k,v in StudentGrades.items():
# v is the list of grades for student k
avgDict[k] = sum(v)/ float(len(v))
But I get the error code:
TypeError: unsupported operand type(s) for +: 'int' and 'str'
And I have also tried:
for names, scores in class1.items():
print("{} : {}".format(names, mean(scores))
But I get the error code:
Traceback (most recent call last):
File "C:/Users/Onyeka/Documents/Onyeka/Computer Science/Controlled ` Assessment/Programming Project/task3.py", line 68, in <module>`
print("{} : {}".format(names, mean(scores)))
File "C:\Python34\lib\statistics.py", line 331, in mean
T, total, count = _sum(data)
File "C:\Python34\lib\statistics.py", line 161, in _sum
for n,d in map(_exact_ratio, values):
File "C:\Python34\lib\statistics.py", line 247, in _exact_ratio
raise TypeError(msg.format(type(x).__name__))
TypeError: can't convert type 'str' to numerator/denominator