3 ms·
>>> row = [""] * 3 #row i['', '', ''] >>> board = [row] * 3 >>> board[0][0] = "X" >>> board [['X', '', ''], ['X', '', ''], ['X', '', '']] I almost felt hel
by giu 6y ago
>>> row = [""] * 3 #row i['', '', '']
>>> board = [row] * 3
>>> board[0][0] = "X"
>>> board
[['X', '', ''], ['X', '', ''], ['X', '', '']]
I almost felt helpless for an hour when I used this list initialization [0] the first time in my code and couldn't find the reason why my unit tests where failing.
[0] https://github.com/satwikkansal/wtfpython#-a-tic-tac-toe-where-x-wins-in-the-first-attempt https://github.com/satwikkansal/wtfpython#-a-tic-tac-toe-whe...