References:
Thank you so much to Mad Physicist, cdrake and Rafael for your suggestions which steered me in the direction I needed to be in to reach the answer.
Answer:
The trick is to never make assignments such as C = B; B = A;, as this will cause loss of information when variables start referring to new objects and the old objects are abandoned and left for some variables to uselessly refer to.
Instead we must make each of these already declared objects to store information as to how to reach the end of the chain. This can be done by:
# Initial Declaration
A = []; B = []; C = []; D = []
# Chain Formation
C.append(B)
B.append(A)
D.append(C)
# Data Addition at Chain head
A.append("DATA")
This gives:
>>> A
['DATA']
>>> B
[['DATA']]
>>> C
[[['DATA']]]
>>> D
[[[['DATA']]]]
Now each of the variables has access to the data added at Chain Head. This data can be obtained by repeatedly entering the into the index 0 of the list till we reach an object which is not of type <class 'list'>. The implementation given below will make it clear:
def GetData(Chain):
C = Chain.copy()
while len(C) > 0 and type(C[0]) == type([]):
C = C[0]
if len(C):
return C[0]
else:
return None
>>> ( GetData(A), GetData(B), GetData(C), GetData(D) )
('DATA', 'DATA', 'DATA', 'DATA')
This way of storing information so as to direct the preceding members to the same source of information as the head of the Chain is very helpful as it can instantly relay the change of final information to the members at the back. An example which builds over the previous code is shown below:
# Initial Declaration for New Chain
P = []; Q = []
# New Chain Formation
Q.append(P)
# Old Chain Redirection
C.remove(C[0])
C.append(Q)
# Attempted Data Recovery
>>> ( GetData(A), GetData(B), GetData(C), GetData(D), GetData(P), GetData(Q) )
('DATA', 'DATA', None, None, None, None)
# Data Addition at New Chain Head
P.append((0,0))
# Attempted Data Recovery
>>> ( GetData(A), GetData(B), GetData(C), GetData(D), GetData(P), GetData(Q) )
('DATA', 'DATA', (0, 0), (0, 0), (0, 0), (0, 0))
This is my solution to the problem I was facing. Please feel free to suggest changes if needed.
Once again, Thank you to all those who directed me to this solution.
A = B = C = []?C = Bmeans thatCandBnow refer to the same list.B = Ameans thatBandAnow refer to the same list. So you now just have two lists, those originally assigned toB(now referenced byC) andA(now referenced byB).