I have an 2D array called 'arr' which I copy but when I change the copy it also changes the original.
Code:
def play(arr):
for row in range(len(arr)):
for column in range(len(arr[row])):
if arr[row][column] == '':
tempArr = arr.copy()
tempArr[row][column] = 'a'
print(arr)
play([['', ''], ['', '']])
Output:
[['a' 'a']
['a' 'a']]
Expected output:
[['' '']
['' '']]
But this doesn't happen if in a 1D array:
def play(arr):
for row in range(len(arr)):
if arr[row] == '':
tempArr = arr.copy()
tempArr[row] = 'a'
print(arr)
print('Temp arr: ' + str(arr))
play(['', ''])
Output:
['' '']
tempArr: ['' 'a']
What can I do about this?
Thanks for helping!