Nov-19-2020, 08:25 PM
Your initial problem was that you were not making different lists, but just several copies of one list. The construction:
[[]] * num
takes the inside list and makes num references to it, but they're all the same list. So each time through was overwriting the previous trips through the loop.>>> players = [[0] * 4] * 3 >>> players [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] >>> players[0][1] = "x" >>> players [[0, 'x', 0, 0], [0, 'x', 0, 0], [0, 'x', 0, 0]]For this to work, you'd need to make different lists.
>>> players = [[0] * 4 for x in range(3)] >>> players [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] >>> players[0][1] = "x" >>> players [[0, 'x', 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]