SIZE = 4 # Author: James Tam # Version: May 25, 2021 # Learning concepts: how to properly (and improperly) copy data from # one list to another. #Copy data from list to another requires that the program manually copies #each list element from one list to another. def copy(destination,source): for r in range (0,SIZE,1): for c in range (0,SIZE,1): destination[r][c] = source[r][c] # Creating reference to grid def create(): aGrid = [["*","*","*","*"], ["*","*","*","*"], ["*","*","*","*"], ["*","*","*","*"]] return(aGrid) def display(aGrid): # Displaying the grid for r in range (0,SIZE,1): for c in range (0,SIZE,1): print(aGrid[r][c], end="") print() def start(): aGrid1 = create() print("Original list") display(aGrid1) #Not copying of lists aGrid1 & aGrid2 refer to the same 2D list print("\nINCORRECT: both aGrid1, aGrid2 refer to the same list") aGrid2 = aGrid1 aGrid1[3][3] = "!" #Modifies same list! print("First list") display(aGrid1) print("Second list") display(aGrid2) #Copying data from list to another print("\nCORRECT: aGrid1 and aGrid2 refer to two separate lists") aGrid2 = create() #Create new list otherwise aGrid2 would still refer to same list as aGrid1 copy(aGrid1,aGrid2) aGrid1[0][0] = "?" aGrid1[3][3] = "?" print("First list") display(aGrid1) print("Second list") display(aGrid2) start()