0

I need to create a string that returns the characters from the column of the board with index column_index as a single string.

I need to return the below

>>> make_str_from_column([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 1)
'NS

I had initially done

def makedef make_str_from_column(board, column_index):
    """ (list of list of str, int) -> str """
    if column_index >=0:
        return board[0][column_index] +board[1][column_index]

however, I cannot use the 0 and 1 these are really just hardcoded to get me to the answer I want

I am a bit lost on how to replace the 0 and 1

Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96
  • Welcome to Stackoverflow! Please edit your question to format the code samples as code. Highlight it and click on the { } button – jwebb Sep 20 '18 at 14:25

1 Answers1

0

Something like this

def makedef make_str_from_column(board, column_index): 
  if len(board) == 0:
    return ''
  if column_index >=0 and column_index < len(board[0]): 
    return ''.join([board[i][column_index] for i in range(len(board))])
Atul Shanbhag
  • 636
  • 5
  • 13