I initialized an empty 2-dimensional list in python:
memories = []
for idx in range(x_size):
memories.append([Dot(0,0)]*y_size)
where Dot
is a class:
def __init__(self, x, y):
self.x = x
self.y = y
Afterwards, I fill the list memories
with content, as follows:
memories[p.state.x][p.state.y].y += 1
The problem is that for some reason, the new value is updated not only in the single cell memories[p.state.x][p.state.y]
but rather also in the whole row memories[p.state.x]
. Why does this happen and how can I avoid it?
Thanks :)