I am calling a function making a copy of the list passed in first, making changes to the copied list and then returning it but changes still occur to the original list.
def moveDown(grid):
tempgrid=grid[:]
for i in range(3):
if 0 in tempgrid[i]:
loc=i
if loc==0:
return None
else:
index=tempgrid[loc].index(0)
tempgrid[loc][index]=tempgrid[loc-1][index]
tempgrid[loc-1][index]=0
return tempgrid
if __name__=="__main__":
x=[[1,2,3],[4,0,6],[7,5,8]]
# puzzleSolve(x)
printGrid(x)
y=moveDown(x)
printGrid(x)
printGrid(y)
this is printed.
******************
1 2 3
4 0 6
7 5 8
******************
******************
1 0 3
4 2 6
7 5 8
******************
******************
1 0 3
4 2 6
7 5 8
******************