if i == -1:
    sys.exit(a)
excluded_numbers = set()
for j in range(81):
    if same_row(i, j) or same_col(i, j) or same_block(i, j):
        excluded_numbers.add(a[j])
for m in '123456789':
    if m not in excluded_numbers:
        r(a[:i] + m + a[i + 1:])
if __name__ == '__main__':
    if len(sys.argv) == 2 and len(sys.argv[1]) == 81:
        r(sys.argv[1])
else:
    print('Usage: python sudoku.py puzzle')
print('  where puzzle is an 81 character string representing the puzzle read left-to-right, top-to-bottom, and 0 is a blank')
Самый короткий решатель судоку в Python — как это работает?