I was wondering in how does exactly deepcopy work in the following context:
from copy import deepcopy
def copyExample:
self.myDict = {}
firstPosition = "First"
firstPositionContent = ["first", "primero"]
secondPosition = "Second"
secondPositionContent = ["second"]
self.myDict[firstPosition] = firstPositionContent
self.myDict[secondPosition] = secondPositionContent
return deepcopy(self.myDict)
def addExample(self):
copy = self.copyExample()
copy["Second"].add("segundo")
Does it return the reference to the lists I have in the dictionary? Or does it work as I expect and copy every list in a new list with a different reference?
I know what a deep copy is (so there is no need to explain the difference between deep and shallow) but I am wondering if it works as I expect it to do and therefore do not change the instance variable when I use addExample()
.