What do I need to make this work?
def get_column(game, col_num):
board = [['O', 'X', 'O'], ['X', ' ', ' '], ['X', ' ', ' ']] column1 = get_column(board, 0) print(column1)
and the result should be ['O', 'X,' 'X']
What do I need to make this work?
def get_column(game, col_num):
board = [['O', 'X', 'O'], ['X', ' ', ' '], ['X', ' ', ' ']] column1 = get_column(board, 0) print(column1)
and the result should be ['O', 'X,' 'X']
Use a list comprehension to access the corresponding column in each row.
def get_column(board, col_num):
return [ row[col_num] for row in board ]
Should look something like this:
def get_column(board, col_num):
return [i[col_num] for i in board]
board = [['O', 'X', 'O'], ['X', ' ', ' '], ['X', ' ', ' ']]
column1 = get_column(board, 0)
print(column1)