So I'm using a nested list to store some data and I'm having trouble with changing specific values of one of the sublists:
if attributes[3] == 'W':
self.board[3][3] = 'W'
(numbers are placeholders i'm using to test)
board is a class variable that is created as follows (I'm trying to create a grid as specified by a user, with their input for column and row sizes making up the first two parts of attributes)
self.board = []
rows = []
self.score = [0, 0]
for x in range(attributes[0]):
rows.append('')
for y in range(attributes[1]):
self.board.append(rows)
However, whenever I try to change the value of a sublist, it changes the values for all sublists for that same index:
[['', '', '', 'W', '', '', '', ''], ['', '', '', 'W', '', '', '', ''], ['', '', '', 'W', '', '', '', ''], ['', '', '', 'W', '', '', '', ''], ['', '', '', 'W', '', '', '', ''], ['', '', '', 'W', '', '', '', ''], ['', '', '', 'W', '', '', '', ''], ['', '', '', 'W', '', '', '', '']]
I can't figure out what's wrong. Anyone have any ideas?