Hello experienced python programmers! I come here in humble request of your guidance on my latest python endeavor.
I'm writing my first program to make heavy use of lists within lists, and i've run into a rather unexpected problem. just for practice, I'm writing a program that simulates a simple ecosystem with three animals: plants, prey and predators. The section of code I have here says that when a plant reaches a certain size (the size is specified in the list of values that defines the plant) it splits in two, and its offspring's attributes are modified slightly, like natural mutations in biology.
Nplants.append(plant)
if plant[2]>plant[3]:#this path spawns another plant
Nplants.append(plant)#the baby is spawned
Nplants[-2][2]=Nplants[-2][2]/2#halves size of old plant
Nplants[-1][2]=Nplants[-1][2]/2#halves size of new plant
Nplants[-1][0]= Nplants[-1][0]+random.gauss(0.0,Nplants[-1][4])#changes x coordinate
Nplants[-1][1]= Nplants[-1][1]+random.gauss(0.0,Nplants[-1][4])#changes y coordinate
Nplants[-1][3]=Nplants[-1][3]+random.gauss(0,10)#changes split size
Nplants[-1][4]=Nplants[-1][4]+random.gauss(0.0,0.5)#changes spawn radius
else:#this path just grows the plant by ten size units
Nplants[-1][2]=Nplants[-1][2]+10
if Nplants[-1][2]<1:#this checks to see if the plant's size is less than one
del Nplants[-1]#kills the plant
My problem is this: all modifications made to the new plant Nplants[-1] also apply to the old plant and vice versa. Why is this and how can I fix it?