Hi there I created a (what I call) nested dictionary:
gradeDict = {
"Intro to Programming":{
"student":{
"firstname":"Mike",
"lastname":"Miller",
"marks":{
"PS01":70,
"PS02":80
}
}
}
}
print(gradeDict['Intro to Programming']['student']['marks'])
which after asking for the values in key 'marks' gives the values
{'PS01': 70, 'PS02': 80}
That's perfect. Now I want add a NEW (key,value) pair to the superior key 'marks':
gradeDict.update( {"Intro to Programming":{ "student":{ "firstname":"Mike",
"lastname":"Miller","marks":{ "PS03":10}}}} )
print(gradeDict['Intro to Programming']['student']['marks'])
Unfortunately this gives
{'PS03': 10}
which I don't understand, a key should only be overwritten if it already exists, otherwise appended. 'marks' exists, but 'PS03' doesn't. What am I missing here, or how to get the desired entry:
{'PS01': 70, 'PS02': 80, 'PS03': 10}
Thanks a lot...