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)
외부 루프를 제거하십시오. 내부 루프에 대해'for board [row_index] :'를 수행하십시오. 또는 모든 루프를 제거하고'return ''.join (board [row_index])'를 호출하십시오. –
감사합니다. @StevenRumbalski 매우 명확하고 간결한 설명! – sim