def helper(mat):
    for row in mat:
        zero_list = []
        for subrow in row:
            if subrow == 0:
                row.remove(0)
                zero_list.append(0)
        row.extend(zero_list)
    return mat
def merge_left(mat):
    result = mat.copy()
    helper(mat)
    counter = 0 
    for i in range(len(mat)):
        current_tile = 0
        for j in range(len(mat)):
            if mat[i][j] == current_tile:
                mat[i][j-1] *= 2
                mat[i][j] = 0
                counter += mat[i][j-1]
            current_tile = mat[i][j]
    helper(mat)
    return result == mat
print(merge_left([[2, 2, 0, 2], [4, 0, 0, 0], [4, 8, 0, 4], [0, 0, 0, 2]]))
Hey guys,
The result I get for merge_left in the above code is True for the test case. Given that result is a duplicate copy of mat. How is it so that result has also been altered in a similar way to mat through this code? I'd understand this to be the case if I had written
result = mat instead of result = mat.copy()
Why is this the case? I'm aiming to compare the two states of the input mat. Before the code alters mat and after it does.
 
    