...

/

Solution Review: Sudoku

Solution Review: Sudoku

We'll cover the following...

Let’s see the solution to the previous challenge.

Solution

Press + to interact
def generate_grid(n_rows, n_cols):
row = [0] * n_cols
grid = [row[:] for _ in range(n_rows)]
# 2 more possible ways of doing the same.
# grid = [row.copy() for _ in range(n_rows)]
# grid = [[0] * n_cols for _ in range(n_rows)]
return grid
def assign(grid, row, col, value):
grid[row][col] = value
return grid
rows, cols = 9, 9
sudoku = generate_grid(rows, cols)
print(assign(sudoku, 1, 0, 9))

...