forループを使用して、リストのリスト内でリストを検索します。特定のリストをリストのリストから、forループを使用して返します。
なぜリスト2ではなくリスト0が返されますか?
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([['H', 'O', 'U', 'S', 'E'], ['B', 'E', 'D'], ['C', 'H', 'E', 'E', 'S', 'E']], 2)
'CHEESE'
"""
letter = ''
line = ''
for row_index in board:
for letter in row_index:
line = line + letter
return line
make_str_from_row([['H', 'O', 'U', 'S', 'E'], ['B', 'E', 'D'], ['C', 'H', 'E', 'E', 'S', 'E']], 2)
外部ループを取り除くことができます。あなたの内部ループのためにボード上の文字を 'row_index:'にしてください。または、すべてのループを取り除き、 'return '' .join(board [row_index])'だけを取り除く。 –
ありがとう@StevenRumbalski非常に明確で簡潔なexplaination! – sim