I have a Sudoku Board as this list,
board = [ ['.', 2, '.', '.', '.', 4, 3, '.', '.'],
[9, '.', '.', '.', 2, '.', '.', '.', 8],
['.', '.', '.', 6, '.', 9, '.', 5, '.'],
['.', '.', '.', '.', '.', '.', '.', '.', 1],
['.', 7, 2, 5, '.', 3, 6, 8, '.'],
[6, '.', '.', '.', '.', '.', '.', '.', '.'],
['.', 8, '.', 2, '.', 5, '.', '.', '.'],
[1, '.', '.', '.', 9, '.', '.', '.', 3],
['.', '.', 9, 8, '.', '.', '.', 6, '.'] ]
I can easily check a certain value is present in a row or not so effortlessly by,
value in board[row][:]
but I can't do the same thing for a column. For example, when I write value in board[:][col]
it somehow picks the row
, indexed with the value col
and then tries to find the specified value
.
For example, print(board[6][:])
gives ['.', 8, '.', 2, '.', 5, '.', '.', '.']
(7th row) and print(board[:][2])
gives ['.', '.', '.', 6, '.', 9, '.', 5, '.']
(3rd row).
I'm really confused why it is the case.
My question is, is there an equivalent syntax of board[row][:]
for a column? And more importantly why board[:][col]
doesn't work?