1def make_move(board, row, col, player):
2 import copy
3 new_board = copy.copy(board)
4 new_board[row][col] = player
5 return new_board
6
7board = [['.', '.', '.'],
8 ['.', '.', '.'],
9 ['.', '.', '.']]
10
11new = make_move(board, 1, 1, 'X')
12print(board[1][1]) # prints 'X', should still be '.'
no lines flagged
#041PracticeEasy10 min · 50 XP
Shallow Copy Mutates Nested List
A function that clones a 2D board for game state unexpectedly mutates the original board.
Flagged linesNo lines flagged yet
What's wrong?
Flag a line or write a note to submit.