A List Comprehension Puzzler
Sometimes, we need to initialize a list with a certain number of nested lists, for example, a list with 3 lists of length 3 that can represent a Tic-tac-toe board. >>> board = [[''] * 3] * 3 >> board [['', '', ''], ['', '', ''], ['', '', '']] >> board[1][2] = 'X' >> board [['', '', 'X'], ['', '', 'X'], ['', '', 'X']] The output is not expected, why? ...