I have a python list that I want to append a list to. The list was declared like this:
data = []
Then I append the list with:
[0, 0, 0, 0, 0, 0, 0, 1, 0]
After that I want to append another list:
[0, 0, 0, 0, 0, -1, 0, 1, 0]
Then when I print out the entire list it shows:
[[0, 0, 0, 0, 0, -1, 0, 1, 0], [0, 0, 0, 0, 0, -1, 0, 1, 0]]
When I am trying to have it print out:
[[0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, -1, 0, 1, 0]]
Where it updated the first element of the array when I just appended it like this:
data.append(prev_board)
And prev_board stores the list to append to the list. My entire code for this is:
def gather_training_data(games):
global data
global game_won
for each_game in range(games):
game = Game()
while True:
pygame.event.get()
game.create_board()
if not game_won:
prev_board = game.board
move = game.random_move()
data.append(prev_board)
print data
time.sleep(5)
else:
break
game_won = False
time.sleep(1)
window.fill((255, 255, 255))
return data
So why are the first elements of the list updating when I am only appending a list to the list?