Currently I am trying to place a word in a column of 2D array in Python 3.6
def __init__(self) -> None:
self.board = [["."] * 10] * 10
self.board[0][0] = 'T'
def printBoardToTerminal(self):
for index in range(0,10):
print()
print(self.board[index], end=" ")
Expected:
['T', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['.', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['.', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['.', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['.', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['.', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['.', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['.', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['.', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['.', '.', '.', '.', '.', '.', '.', '.', '.', '.']
Actual:
['T', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['T', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['T', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['T', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['T', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['T', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['T', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['T', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['T', '.', '.', '.', '.', '.', '.', '.', '.', '.']
['T', '.', '.', '.', '.', '.', '.', '.', '.', '.']
I thought it was a printing error but when I print(self.board)
it also shows that the first element in each row is 'T'
.
Edit: I tried doing the same above with the numpy
library instead creating a 2D array of characters and then the replacement works as expected but with the above implementation still not sure whats going on there :/