Bottom Page

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.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)