List of Lists of Object referencing same object in Python
python
Solution
You have it reversed: you are creating 9 independent `Board` instances there. If you had something like
largeBoard = [[Board()] * 3] * 3
then you would only have a single instance. This is the root of a common mistake that many Python newcomers make.
`[X for i in range(3)]` evaluates `X` once for each `i` (3 times here) whereas `[X] * 3` evaluates `X` only once.
Problem
I'm fairly new to Python and so I'm not extremely familiar with the syntax and the way things work exactly. It's possible I'm misunderstanding, but from what I can tell from my code this line: ``` largeBoard = [[Board() for i in range(3)] for j in range(3)] ``` is creating 9 references to the same Board object, rather than 9 different Board objects. How do I create 9 different Board objects instead? When I run: ``` largeBoard = [[Board() for i in range(3)] for j in range(3)] x_or_o = 'x' largeBoard[1][0].board[0][0] = 'g' # each Board has a board inside that is a list for i in range(3): for j in range(3): for k in range(3): for l in range(3): print largeBoard[i][j].board[k][l] ``` I get multiple 'g' that is what made me think that they are all references to the same object.