A demonstration of shallow vs deep copying. This was the source of many student bugs in tippy's apply_move method. Make sure you understand this! 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] Python Type "help", "copyright", "credits" or "license" for more information. # A list that we want to keep intact. # We're going to try several ways to make a copy of it, and see which # succeed in keeping L1 intact. L1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # This definitely won't work. L1 and L2 are references to the same list # object! This didn't likely trip up many of you. L2 = L1 id(L1) 4316207304 id(L2) 4316207304 # Here we copy L1 instead. L2 = [r for r in L1] L2 [[1, 2, 3], [4, 5, 6], [7, 8, 9]] L1 [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # See that L2 is a different list than L1. Everything should be fine, right? id(L2) 4314697672 # Let's change L2 and find out. L2[1][1] = 999999999 L2 [[1, 2, 3], [4, 999999999, 6], [7, 8, 9]] L1 [[1, 2, 3], [4, 999999999, 6], [7, 8, 9]] # Oh no! L1 is different too. # We did not protect ourselves against changes within the sublists: # Although L1 and L2 are two different list objects, at each index # they both refer to the same list object (for the sub-lists that # represent rows). id(L1) 4316207304 id(L2) 4314697672 # See -- same memory addresses: id(L1[1]) 4316207688 id(L2[1]) 4316207688 # (But we did protect L1 against changes to L2 at the top level, because # they are two different list objects at that level.): L2[0] = "hello" L2 ['hello', [4, 999999999, 6], [7, 8, 9]] L1 [[1, 2, 3], [4, 999999999, 6], [7, 8, 9]] # Okay, L1 is been changed. Let's make another attempt to copy it, and # try not to change L1 any further. L1 [[1, 2, 3], [4, 999999999, 6], [7, 8, 9]] # Here we make copies at both levels of the list: L3 = [[item for item in r] for r in L1] id(L3) 4314177608 id(L1) 4316207304 # Not only are L1 and L3 different list objects, but their elements are too: id(L3[1]) 4316009608 id(L1[1]) 4316207688 # So when we change L3 in a sublist, L1 does not change. L3[2][1] = -42 L3 [[1, 2, 3], [4, 999999999, 6], [7, -42, 9]] L1 [[1, 2, 3], [4, 999999999, 6], [7, 8, 9]] # L3 was a successful "deep copy" of L1.