[Python-Dev] copy() and deepcopy()
raymond.hettinger at verizon.net
Sat Nov 22 01:47:12 EST 2003
I would like to confirm my understanding of copying and its
A shallow copy builds only a new outer shell and leaves the inner
references unchanged. If the outer object is immutable, then a copy
might as well be the original object. So, in the copy module, the copy
function for tuples should just return the original object (the function
looks like it does more but actually does return itself). And, since a
frozenset is immutable, its copy function should also just return self.
The point of a deepcopy is to replace each sub-component (at every
nesting level) that could possibly change. Since sets can only contain
hashable objects which in turn can only contain hashable objects, I
surmise that a shallowcopy of a set would also suffice as its deepcopy.
For frozensets, shallowcopy == deepcopy == self
For sets, shallowcopy == deepcopy == set(list(self)) # done with
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev