0

I'm trying to generate a Sudoku. I thought about using an array for this. THis is how I create the array (ignore the fact that these are not correct Sudoku numbers):

row_array = [[1, 99],[2],[3], [4], [5], [6], [7], [8], [9]]

It does work fine. The problem is with an if statement. If I do:

print(row_array[0][1])

or:

r = 1
print(row_array[0][r])

to get the "99" it does work fine! But if I use this variable method in an if statement like this:

if y not in row_array[1] and y not in row_array[0][r]:
    row_array[1].append(y)

I get the following ERROR:

TypeError: argument of type 'int' is not iterable

I had the Sudoku working, but it took to much code, so I want to set up a counter to replace the rows and columns with an it. I'm aware of you guys probably already having a much better code for a sudoku, but I want to teach myself, and make the code better and shorter over time. I don't learn to code real good, by just copy someone else's idea or way to code.

3
  • Hello! Can you elaborate on how you expect the row_array to look if the append call succeeds? Commented Sep 23, 2018 at 14:10
  • by y not in row_array[0][r] you mean between 1 and 99 ? Commented Sep 23, 2018 at 14:13
  • That is because row_array[0][r] is no more a sublist but a scalar Commented Sep 23, 2018 at 14:20

1 Answer 1

1

The problem is here:

if y not in row_array[0][r]

The in operator checks if the left-hand side is in the sequence or iterable on the right hand side. But type(row_array[0][r]) will return int, which is not an iterable.

Sign up to request clarification or add additional context in comments.

3 Comments

Typo: if y not int -> if y not in
Thank you. But how do i fix this? I have no clue how to check otherwise then that.
Use if y == row_array[0][r].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.