[docs] https://docs.python.org/2/library/copy.html apparent error
Zachary Ware
zachary.ware+pydocs at gmail.com
Thu Sep 29 00:36:17 EDT 2016
Hi Andrew,
On Tue, Sep 27, 2016 at 9:13 PM, Andrew Jarcho <andrew.jarcho at gmail.com> wrote:
> Hi,
>
> I believe the following line in the above page of the Python 2.7.12
> documentation:
>
>>> Shallow copies of dictionaries can be made using dict.copy(), and of
>>> lists by assigning a slice of the entire list, for example, copied_list =
>>> original_list[:].
>
> should read:
>
>>> Deep copies of dictionaries...
Thanks for the report! However, the line is accurate as written:
dict.copy() does indeed do a shallow copy:
>>> l = []
>>> d = dict(l=l)
>>> d2 = d.copy()
>>> l.append('Not a deep copy')
>>> d2
{'l': ['Not a deep copy']}
If you want a deep copy of a dict, you'll need to use the deepcopy() function.
Regards,
--
Zach
More information about the docs
mailing list