Update datastructures.rst by dovanquyet · Pull Request #26033 · python/cpython
Dear Dennis, In the first example, x and y are actually different objects. Try x.append('c') and show both x and y again to see the difference. That is why I say this is a deep copy. It really depends on the data structure of elements in x to say if those elements are shallowly or deeply copied to y, but in terms of x and y only, the copy is deep, different from "x = y" which I call shallow copy. Regards, Quyet.
…On Tue, May 11, 2021 at 11:26 PM Dennis Sweeney ***@***.***> wrote: I think the docs should remain as is. Consider: # Shallow Copy: just copy over the two pointers>>> x = [["a"], ["b"]]>>> y = x.copy()>>> x[0] is y[0]True>>> x[0].append("c")>>> x [['a', 'c'], ['b']]>>> y [['a', 'c'], ['b']] # Deep Copy: recursively copy over the contents of the two lists>>> from copy import deepcopy>>> x = [["a"], ["b"]]>>> y = deepcopy(x)>>> x[0] is y[0]False>>> x[0].append("c")>>> x [['a', 'c'], ['b']]>>> y [['a'], ['b']] While it's correct that list.copy() makes a copy (not just an alias like y = x), it is not a deep copy, since the *contents* are just aliased. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#26033 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALINIJ5FKK7XZX5EU25COETTNFEDNANCNFSM44VLKCUQ> .
-- ********************************* Đỗ Văn Quyết Mobile: +84-(0) 982 910 568 Email: ***@***.***