I am trying to create a tic tac toe program, and I need to return a diagonal in a 3x3 matrix.
Say my board looks like this:
board = [
["a", "x", "b"],
["c", "o", "d"],
["e", "f", "g"]
]
I have for the forward matrix:
diag = [board[i][i] for i in range(len(board))]
which returns:
>>> diagonal(board, 1)
['a', 'o', 'g']
(If possible can someone explain to me why this works. I'm not so good with comprehending lists...).
How would I go about getting the reverse? say, ['b', 'o', 'e']?
Thank you!