![]() |
|
attrdict.py - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: Code sharing (https://python-forum.io/forum-5.html) +--- Thread: attrdict.py (/thread-15082.html) Pages:
1
2
|
RE: attrdict.py - nilamo - Jan-13-2019 I have no idea, but I want to guess it would not. >>> x = {"a": [1, 2, 3]}
>>> y = {}
>>> y.update(x)
>>> x
{'a': [1, 2, 3]}
>>> y
{'a': [1, 2, 3]}
>>> x["a"].append(4)
>>> x["b"] = 2
>>> x
{'a': [1, 2, 3, 4], 'b': 2}
>>> y
{'a': [1, 2, 3, 4]}
>>> y["a"].append(5)
>>> x
{'a': [1, 2, 3, 4, 5], 'b': 2}
>>> y
{'a': [1, 2, 3, 4, 5]}So it makes a shallow copy, but mutable objects (like lists) aren't copied, they're shared.
|