|
I'm trying to solve the Suduko problem by using a nested loop, and the zip function. When I run the initial list/matrix through my loop, it returns the correct values. However, when I run the zipped version of the list through the exact same loop (or a copy redefined as a separate function), it tells me it can't pop because there aren't any values in the list. I really don't understand why that is. By creating a new list with the the zip function, shouldn't it have values in it? And, when I run my code through the visual interpreter at: http://people.csail.mit.edu/pgbovine/python/tutor.html#mode=edit, it even displays the zipped matrix as a list. I'd post the code here, but I know we're not supposed to do that. |
With all due respect, why are you trying to incorporate functions not yet presented in order to solve the homework? Especially if they are increasing the difficulty of assignment?
It seemed that the zip function was a quick and easy way to get the data represented by the columns, as we had the data listed in rows. Also, it seems logical that if one sums both the columns and the rows, then compares these sums, it is the easiest way to test whatever size Suduko square. Just testing the rows wouldn't work because you can have all of correct numbers in the puzzle, but not in the correct order.
Have you tried printing the zipped list to verify that it does have values (in the interpreter where you are having problems)?
I agree with others here. You should try to stick with the functions we know as of now. Even though some other functions could make the problem a lot easier, we are not trying to make things easy, we are trying to learn. Making a somewhat complicated but interesting and nuanced solution is what we are aiming for. We aren't looking for the best possible way to check if something is a sudoku, we are leaning how to execute various random tasks for the sake of learning.
When dealing with sums of columns and rows, make sure your code will handle something like [[1,4,4,1],[4,1,1,4],[4,1,1,4],[1,4,4,1]]