This line is a problem:
tempBoard = genBoard
After this line, you seem to think that you have two lists -- the original, still referenced
by genBoard
, and a new one, now referenced by tempBoard
. This is not the case.
This line does not create a copy of the list. Instead, it binds the name tempBoard
to refer to the same object that genBoard
is bound to.
Consequently, subsequent references to tempBoard[i]
also affect genBoard[i]
.
Try one of these instead:
tempBoard = list(genBoard)
tempBoard = genBoard[:]
tempBoard = copy.copy(genBoard)
Each of these lines creates a new list, the initial contents of which is the same as genBoard
. tempboard
is bound to this new list, while genboard
remains bound to the old list.
If the object in question were more complicated than a list of strings, you might need to do this:
tempBoard = copy.deepcopy(genBoard)