I have a python list:
x = [1,1,1]
I set y equal to that list and then change y, and x changes because I have two pointers to the same place in memory.
y = x
y[1] = 7
print x
[1, 7, 1]
That's all good. Is there anyway I can make a list of x+y so that when I change x, I also change y? Here's some code which doesn't work but maybe clarifies my goal:
q = x + y
print q
[1, 7, 1, 1, 7, 1]
q[0] = 2
print q
[2, 7, 1, 1, 7, 1]
but I'd LIKE q to instead become:
[2, 7, 1, 2, 7, 1]
I hope that's clear, and I hope even more that it's achievable!
EDIT: To respond to the inquiries as to why this would be useful, I intend to use it as a ring buffer. Say I want to take the contents at position p and move them to position p+1: Instead of:
if p+1 == len(q):
q[0]= q[p]
else:
q[p+1] =q[p]
I could just do:
q[p+1] = q[p]