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_colsgrid = [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 griddef assign(grid, row, col, value):grid[row][col] = valuereturn gridrows, cols = 9, 9sudoku = generate_grid(rows, cols)print(assign(sudoku, 1, 0, 9))
...