I want to be able to reset a nested list of Boolean values lists to a particular configuration once a certain condition has been reached inside a for loop.
So at the start of my program I define the list as follows:
g = [[True,True,False,False,False],[True,False,False,False,False],[False,False,False,False,False],[False,False,False,False,False],[False,False,False,False,False]]
Then I have a for loop:
for i in range(10):
row = random.randrange(5)
col = random.randrange(5)
print str(col) + "\t" + str(row)
gridC = doMove(gridC,col,row)
s += str(col + 1) + "\t" + str(row + 1) + "\n"
for i in gridC:
print i
if isFound(gridC[:]):
found = True
break
else:
s = ""
gridC = g[:]
The loop terminates if all values in gridC
are false. However when I try to reset gridC
to g[:]
, it retains the memory of being changed in previous iterations of the loop. I can't work out any way of reliably resetting it to the correct configuration each time.
Edit Note: I am aware of the thread that explains copying a list but as you can see at the bottom of my for loop I have tried this with gridC = g[:]
. The problem still persists and I cannot work out why.