Python Forum
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
attrdict.py
#11
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020