I am trying to work with a particular object in many instances of a class. However whenever I am adding a value to that object, turns out it is adding the value to objects of all other instances of the class.
This SO post suggested that I had same id for my objects as the GC freeing up and loading objects on the same memory.
Node class has an object neighbors set as neighbors = []
grid = [[node() for x in range(col)] for y in range(row)]
temp1 = grid[0][0].neighbors
temp2 = grid[4][0].neighbors
print id(temp1)
print id(temp2)
temp1.append("sth")
print temp1
print temp2
Output:
38412376
38412376
['sth']
['sth']
What would be a possible workaround for temp2 to have an empty list?