在某个元素的嵌套列表中检查字符串

时间:2018-12-04 17:58:51

标签: python-3.x nested-lists minesweeper

def isMineAt(gameBoard, row, col) : #doesn't work for some reason

    mainList = []
    mainList.append(row)
    mainList.append(col)
    print (mainList)
    mineAtLocation = False


    #compare the row and column guesses with gameboard[guess1]
    for i in range (GRIDSIZE) :
        for j in range(GRIDSIZE) :
            if gameBoard[mainList[0] == 'x' :
                row = True
            if gameBoard[mainList[2]] == 'x' :
                col = True

    if row == True and col == True :
        mineAtLocation = True
    elif row == False or col == False :
        mineAtLocation = False

我正在使用isMineAt(gameBoard,row,col)调用我的函数

游戏板是我之前初始化的一个嵌套列表,并且row和col是我也要传入的两个整数,并将它们添加到数组中以与我的gameBoard进行比较。我收到一个错误,但是是:

TypeError:列表索引必须是整数或切片,而不是str

0 个答案:

没有答案