I am a python newbie and learning about dictionaries. I have a list of students with their grades and I need to map each student to his grade for a specific exam.
I am using a for loop to iterate over each student name and then another loop to iterate over the exam grades. My code is below but for some reason I am not getting a desired outcome. I hoping someone can point out where I messed up. Thank you.
students = {'Student1': {'Exam1': 80, 'Exam2': 80, 'Exam3': 70},
'Student2': {'Exam1': 90, 'Exam2': 70, 'Exam3': 65}}
student_grades = {}
for student, exam in students.items():
student_grades = {student}
for key,value in exam.items():
student_grades.update({key + ':', value})
print(student_grades)
#This is what I'd like my result to look like:
({'Student1': {'Exam1': 80}}, {'Student1': {'Exam2': 80}}, {'Student1': {'Exam3': 70}}, {'Student2': {'Exam1': 90}}, {'Student2': {'Exam2': 70}}, {'Student2': {'Exam2': 65}})
#But this is what it actually looks like:
{65, 'Student2', 90, 70, 'Exam3:', 'Exam1:', 'Exam2:'}