Sep-20-2018, 01:59 AM
The list is a reference too, just like the dictionary. A shallow copy of the list gives you all the items in the list. But some of those items can be references too. A shallow copy will just give you those references.
>>> x = [1, 2, 3] >>> y = [x, 4, 5] >>> y [[1, 2, 3], 4, 5] >>> z = y[:] # shallow copy >>> y[1] = 6 >>> y [[1, 2, 3], 6, 5] >>> z [[1, 2, 3], 4, 5] # integers that are values don't have changes affect the shallow copy >>> x[1] = 7 >>> z [[1, 7, 3], 4, 5] # lists that are references do have changes affect the shallow copyA deep copy would make an independent copy of everything in the list.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures