Here's a 3*4 matrix represented by embedded list, when I try to assign the dp[0][0][0] = 1
, it changes all first value of each list element.
I'm using python 3.7, don't know where's the problem.
I want to change the first value of first [0,0,0,0] to 4
dp = [[[0,0,0,0]] * 3] *4
dp[0][0][0] =4
print(dp)
output like this
[[[4, 0, 0, 0], [4, 0, 0, 0], [4, 0, 0, 0]], [[4, 0, 0, 0], [4, 0, 0, 0], [4, 0, 0, 0]], [[4, 0, 0, 0], [4, 0, 0, 0], [4, 0, 0, 0]], [[4, 0, 0, 0], [4, 0, 0, 0], [4, 0, 0, 0]]]