items = [[1,2,3],[2,0,4],[3,4,1]]
def findzero(target):
for i,lst in enumerate(target):
for j,n in enumerate(lst):
if n == 0:
return [i, j]
return (None, None)
def move_up(currState):
result = currState[:]
if findzero(result)[0] == 0:
return result
else:
x = findzero(result)[0]
y = findzero(result)[1]
p = result[x - 1][y]
result[x - 1][y] = 0
result[x][y] = p
return result
The result moved the 0 up but when I run the file, the 0 also moved up in the items variable. How can I move the zero up without change the original variable?
move_up(items)
Out[84]: [[0, 2, 3], [1, 2, 4], [3, 4, 1]]
items
Out[85]: [[0, 2, 3], [1, 2, 4], [3, 4, 1]]
I need items do not changed