So I'm trying to create an array visualiser with pygame and have run into a strange problem I can't seem to get around,
here's a small portion of code to recreate the issue
def appendto(array):
temp=[]
for i in range(3):
array.append(i)
temp.append(array)
return temp
array=[]
print(appendto(array))
When I run this code it shows
[[0, 1, 2], [0, 1, 2], [0, 1, 2]]
I am trying to make the temp array record each change made to the main array, but by the end it seems to have only recorded the final state of the array 3 times.
The only half - solution I have found is to turn the array into a string before appending it, doing
array.append(str(i))
but this will slow down my program significantly as I will then have to turn the string back into an array in order to use it.
please do tell me if I'm doing something wrong