sudoku1 = "003020600900305001001806400008102900700000008006708200002609500800203009005010300" sudoku2 = "200080300\n060070084\n030500209\n000105408\n\n000000000\n402706000\n301007040\n720040060\n004010003" sudoku3 = "......9.7\r\n...42.18.\r\n...7.5.26\r\n1..9.4...\r\n.5.....4.\r\n...5.7..9\r\n92.1.8...\r\n.34.59...\r\n5.7......" def parse(s): res = [[0 for y in range(9)] for x in range(9)] x=0 y=0 for c in s: if (c>="0" and c<="9") or (c=="."): if c==".": c="0" res[x][y] = int(c) x+=1 if (x==9): x=0; y+=1 return res print(parse(sudoku1)) print(parse(sudoku2)) print(parse(sudoku3))