2

I'm making a tic-tac-toe game and wanted to make a grid, but when i try to change one value in one nested list then it mirrors to the other nested list.

I made what i think two identical lists and one works and the other doesn't, but when i print them, they are identical.

pole = '| |'
table = [[pole] * 3] * 3
table_1 = [[pole] * 3, [pole] * 3, [pole] * 3]

print(table)
print(table_1)

for row in table:
    print(''.join(row))
for row in table_1:
    print(''.join(row))

row = int(input('Row: '))
column = int(input('Column: '))

table[row][column] = '|x|'
table_1[row][column] = '|x|'

Can someone tell me whats the difference and why that happens?

tasops
  • 43
  • 7

0 Answers0