from collections import defaultdict
test_d={'Maria': {'math':67, 'science':45},
'John' :{'math':88, 'science':90},
'Sarah' :{'math':65, 'science':90},
'Albert' :{'math':74, 'science':60},
'bob' :{'math':100, 'science':65}
}
def calculate_avg(d):
avgs = defaultdict(list)
for k,v in d.items():
for i in v:
avgs[i].append(v[i])
for k,v in avgs.items():
print(sum(v)/len(v))
calculate_avg(test_d)