i have a sudoku generator and the output is like this:
800034065534267891100589304213000706456010000098640502900358000020476109687920050
but i need it to be in this format:
my_sudoku =[
[9,0,0,0,0,0,0,0,5],
[0,0,3,6,0,0,0,0,0],
[0,7,0,0,9,0,2,0,0],
[0,5,0,0,0,7,0,0,0],
[0,0,0,0,4,5,7,0,0],
[0,0,0,1,0,0,0,3,0],
[0,0,1,0,0,0,0,6,8],
[0,0,8,5,0,0,0,1,7],
[7,9,0,8,1,3,4,5,2]]
i need something reverse of this:
def boardToCode(self, input_code=None):
if input_code:
_board = ','.join([str(i) for j in input_code for i in j])
return _board
else:
self.board = ','.join([str(i) for j in self.code for i in j])
return self.board
but i cannot think of anything.
how can i do this?
CodePudding user response:
this should do
board=[list(map(int, my_sudoku[i:i 9])) for i in range(0, 81, 9)]
CodePudding user response:
How about something like this?
def code_to_board(code):
nums = [int(i) for i in code]
board = [nums[i:i 9] for i in range(0, 81, 9)]
return board