1

假设在函数中调用的函数正常工作(确实如此)。我在这里做错了什么?

def board_contains_word_in_column(board, word):
    """ (list of list of str, str) -> bool

    Return True if and only if one or more of the columns of the board
    contains word.


    Precondition: board has at least one row and one column, and word is a
    valid word.

    >>> board_contains_word_in_column([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 'NO')
    False
    """


    for char in range(len(board)):
        if word in make_str_from_column(board,char):
            return True

    return False
4

1 回答 1

6

len(board)是 2。我怀疑你的意思len(board[0])是 4

这是编写函数的更简单方法的提示

>>> board = [['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']]
>>> tuple('NO') in zip(*board)
False
>>> tuple('NS') in zip(*board)
True
于 2013-10-02T00:46:18.180 回答