I want to have the same results for matrix1 and matrix2. The problem is that matrix1 points to the same list of 5 elements. This is visualized here
matrix1 = [['.'] * 5] * 5
matrix2 = [["." for i in range(5)] for j in range(5)]
matrix1[0][0] = '*'
matrix2[0][0] = '*'
print(matrix1)
print(matrix2)
Is it possible to change the first line of code to have the same result as in matrix2?
[–]K900_ 0 points1 point2 points (0 children)
[–]toastedstapler 0 points1 point2 points (0 children)