I would like to access and change a single character in my 2D list of characters. However, when I change one, it changes the whole column. Why is this? What am I doing wrong? At line 31: I am modifying an element in my array and I get a result different than the one I want and expect.
Below is my code:
from random import *
class chessBoard:
BOARD = None
BOARD_WIDTH = 8
def __init__(self,W = 8):
self.BOARD = []
self.BOARD_WIDTH = W
aRow = ['.'] * self.BOARD_WIDTH
for curRow in range(self.BOARD_WIDTH):
self.BOARD.append(aRow)
def printBoard(self):
for curRow in self.BOARD:
print(curRow)
def initialiseRandomQ(self,N):
cords = []
for ii in range(self.BOARD_WIDTH):
for jj in range(self.BOARD_WIDTH):
cords.append( [ii,jj] )
shuffle(cords)
self.BOARD[0][0] = '1'
# for curQ in range(N):
# xx = cords[curQ][0]
# yy = cords[curQ][1]
# print(xx,yy)
# print(cords[curQ])
# self.BOARD[xx][yy] = 'Q'
#PROGRAM START#
N_QUEENS = 2
myChessBoard = chessBoard()
myChessBoard.initialiseRandomQ(2)
myChessBoard.printBoard()