Learn Classes and Objects by Building a Sudoku Solver - Step 32

Tell us what’s happening:

So I have the generator expression in the all() call plus I have the return statement but the terminal shows blank and I still receive an error message?

Your code so far

class Board:
    def __init__(self, board):
        self.board = board

    def find_empty_cell(self):
        for row, contents in enumerate(self.board):
            try:
                col = contents.index(0)
                return row, col
            except ValueError:
                pass
        return None

    def valid_in_row(self, row, num):
        return num not in self.board[row]

# User Editable Region

    def valid_in_col(self, col, num):
        (self.board[row][col] != num for row in range(9))
        all(self.board[row][col] != num for row in range (9))
        return

# User Editable Region

puzzle = [
  [0, 0, 2, 0, 0, 8, 0, 0, 0],
  [0, 0, 0, 0, 0, 3, 7, 6, 2],
  [4, 3, 0, 0, 0, 0, 8, 0, 0],
  [0, 5, 0, 0, 3, 0, 0, 9, 0],
  [0, 4, 0, 0, 0, 0, 0, 2, 6],
  [0, 0, 0, 4, 6, 7, 0, 0, 0],
  [0, 8, 6, 7, 0, 4, 0, 0, 0],
  [0, 0, 0, 5, 1, 9, 0, 0, 8],
  [1, 7, 0, 0, 0, 6, 0, 0, 5]
]

gameboard = Board(puzzle)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36

Challenge Information:

Learn Classes and Objects by Building a Sudoku Solver - Step 32

  1. you have the generator expression twice
  2. what is your function returning?

So does that mean I only need the call to all() generator expression and delete the other line of code?

yes, when you are asked to use an existing piece of code to do something you should not repeat it again, but continue changing that piece of code

So I did what you said but still saying pass to all function?

def valid_in_col(self, col, num):
        all(self.board[row][col] != num for row in range(9))
        return

how do you return something from a function?

So from what I read online it says a return statement followed by an optional return value?

you have a return statement, as there is no return value your function returns None. You are asked to return something from the function

So I tried this now.

def valid_in_col(self, col, num):
        all(self.board[row][col] != num for row in range(9))
        return all(self.board[row][col] != num for row in range (9))

What does it return? Check the output.

Do you get any error messages in the terminal?

If you aren’t looking at the output or checking for error feedback it’s like you’re coding with your eyes closed and guessing.

so now you have the all() function twice, can you explain why you did that?

Ok so I figured out I didn’t need the all() function more than once like you stated but I also had the return statement in the wrong place.