Can someone explain to me why this code (python 2.7):
k=0
img = [[0]*4]*5
for i in xrange(len(img)):
for j in xrange(len(img[0])):
k+=1
img[i][j] = k
print(img)
results in this:
[[17, 18, 19, 20],
[17, 18, 19, 20],
[17, 18, 19, 20],
[17, 18, 19, 20],
[17, 18, 19, 20]]
instead of this:
[[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16],
[17, 18, 19, 20]]
I'm not sure what I'm missing...?