'How can I i get the same result as shown on the docstring

def make_str_from_row(board, row_index):
    """ (list of list of str, int) -> str

    Return the characters from the row of the board with index row_index
    as a single string.

    >>> make_str_from_row([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 0)
    'ANTT'
    >>> make_str_from_row([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 1)
    'XSOB'
    >>> make_str_from_row([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B'], ['F', 'G', 'O', 'L']], 2)
    'FGOL'
    
    """


Solution 1:[1]

Use str.join:

def make_str_from_row(board, row_index):
    """(list of list of str, int) -> str

    Return the characters from the row of the board with index row_index
    as a single string.

    >>> make_str_from_row([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 0)
    'ANTT'
    >>> make_str_from_row([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 1)
    'XSOB'
    >>> make_str_from_row([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B'], ['F', 'G', 'O', 'L']], 2)
    'FGOL'

    """

    return "".join(board[row_index])


print(make_str_from_row([["A", "N", "T", "T"], ["X", "S", "O", "B"]], 0))
print(make_str_from_row([["A", "N", "T", "T"], ["X", "S", "O", "B"]], 1))
print(
    make_str_from_row(
        [["A", "N", "T", "T"], ["X", "S", "O", "B"], ["F", "G", "O", "L"]], 2
    )
)

Prints:

ANTT
XSOB
FGOL

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andrej Kesely