from utils import * from math import * def grid_values(grid): """Convert grid string into {: } dict with '123456789' value for empties. Args: grid: Sudoku grid in string form, 81 characters long Returns: Sudoku grid in dictionary form: - keys: Box labels, e.g. 'A1' - values: Value in corresponding box, e.g. '8', or '123456789' if it is empty. """ assert len(grid) == 81, "Input must be 81 characters" result = {} rowNum = 0 for i in range(0, len(grid)): if i > 0 and i % len(cols) == 0: rowNum = rowNum + 1 rowName = rows[rowNum] colName = cols[i % len(cols)] key = rowName + colName result[key] = grid[i] if grid[i] != '.' else cols return result