我试图在NoneType
发生时切断功能,但即使没有NoneType
.
def solver(integer):
try:
i = integer.index(0)
except ValueError:
return integer
used_integer = [integer[j] for j in range(81)
if not ((i-j)%9 * (i//9^j//9) * (i//27^j//27 | (i%9//3^j%9//3)))]
for j in range(1, 10):
if j not in used_integer:
solved_sudoku = solver(integer[:i]+[j]+integer[i+1:])
if solved_sudoku is not None:
return solved_sudoku
if j in used_integer:
sys.exit('Error')
065000008 700860400 000020009 040001002 000207000 300500070 400050000 001079003 9000002* 66 * <-------具有重复值的数独谜题
当我这样做时,我收到来自班级的错误
class Sudoku(list):
def __init__(self, content):
list.__init__(self, [int(i) for i in content.split()]
if isinstance(content, str) else content)
def __str__(self):
return '\n'.join(
' '.join([(str(j) if j != 0 else '-')
for j in self[i*9:(i+1)*9]]) for i in range(9))
我收到错误(TypeError: NoneType object is not iterable