I understand where my problem is stemming from, I simply do not know how to fix it.
for x in listoflists:
if x[1] == [1,0]:
q=[0, 0]
for z in range(5):
q[z] = x[:]
q[z][1] = [0,1]
q[z][0][-1] = q[z][0][-1] * 1.25
print(id(q[z][0][-1]))
list.append(q)
What I am trying to do is:
- go into some data that I have gathered and make copies where I have switched a data label from
[1,0]
to[0,1]
- then go into the zero index and multiply the price column by some factor to scale it up.
What I currently have is changing all prior values to be what I want the last value to be.
I understand this is something to do with python handling lists as references.
I had to change my first line to be a slice of x
to alleviate this, but I do not know how to get around the parts where I take specifically indexed list items because it is showing the id
as two different memory spaces.
All of the solutions I have seen show list comprehensions but I do not know how that applies to my case, because it seems like my z indexing is working correctly and they all have separate memory ids.