I have a original dictionary - student = {"name":"Mike","class":{"grade":10,"section":"b"}}
. Now, I have another new_dict = {"class":{"grade":10, "section":"c"}}
Now, i wanted to update my student dict with new_dict for matching key, student.update(new_dict) works fine. But I could have cases like new_dict = "class":{"section":"d"}
and when i give update, it updates the student dict and "grade":10
goes missing.
student = {"name":"Mike","class":{"grade":10,"section":"b"}}
new_dict = {"class":{"section":"c"}}
student.update(new_dict)
Actual output:
=============
print(student)
{'name': 'Mike', 'class': {'section': 'c'}}
Expected output:
================
{'name': 'Mike', 'class': {"grade":10,'section': 'c'}}
What is the best way to do an update in this case, update inside all keys and entries and update only the matching key and value(even if it's inside nested).