[Solved ]why does it give a TypeError?

Viewed 47

for context I'm making a function for a sudoku solver that checks the colums and my code is as following

sudoku_grid = [[5, 3, 0, 0, 7, 0, 0, 0, 0],
               [6, 0, 0, 1, 9, 5, 0, 0, 0],
               [0, 9, 8, 0, 0, 0, 0, 6, 0],
               [8, 0, 0, 0, 6, 0, 0, 0, 3],
               [4, 0, 0, 8, 0, 3, 0, 0, 1],
               [7, 0, 0, 0, 2, 0, 0, 0, 6],
               [0, 6, 0, 0, 0, 0, 2, 8, 0],
               [0, 0, 0, 4, 1, 9, 0, 0, 5],
               [0, 0, 0, 0, 8, 0, 0, 7, 9]]
def possible_col(x, y, n):
    for col in range(len(sudoku_grid[x][y])):
        if n == sudoku_grid[x][y]:
            return print("True")
        else:
            return print("False")

possible_col(0,0,2)

this is what I get

1 Answers

Your variable sudoku_grid is a list of lists of ints.

That means sudodk_grid[x] is an array and sudoku_grid[x][y] is an int (assuming that x and y are within the list boundaries).

For your code that means that you are trying to call len() on an int which is not defined.

Related