
Kenneth L. answered 01/13/20
Experienced Computer Science Instructor
I believe the answer that you are looking for is a function that is part of the copy module named deepcopy. It copies contents of a collection recursively, so that you end up with a deep copy rather than a shallow copy. I've included a little example script below which compares the difference between a shallow and deep copy of a dictionary that contains a dictionary (or two in this case).
The copy method which is part of the dict object, only creates a shallow copy. Instead, you should import the copy module (or just the deepcopy function from this module) and use that.