I'm trying to implement a R-Tree datastructure and i have the following RNodeLeaf
class:
class RNodeLeaf(object):
def __init__(self, entries=[]):
self._entries = entries
def addEntry(self, e):
self._entries.append(e)
And i want to distribute some data to the nodes i created. consider this piece of code:
nodes = []
for i in range(8):
if i % 4 == 0:
node = RNodeLeaf()
nodes.append(node)
node.addEntry(5)
print(nodes)
print(nodes[0]._entries)
print(nodes[1]._entries)
So my assumption would be that there were 2 RNodeLeafs
created which is true, as i printed print(nodes)
and both of them have 4 elements.
But then after i print print(nodes[x]._entries)
i was surprised, because they both the same data.
[5,5,5,5,5,5,5,5]
So what am i missing and what can be done to fix this error?