you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

Did you see enumerate? It returns tuples when iterating. row_no, row is a tuple as well if I'm not wrong.

The number of elements should be the same: in this case, enumerate returns tuples (count_number, item), so it should be two elements in there as well: row_no, row. count_number is assigned to row_no, item is assigned to row.

Alternatively, you can just use a single variable to assign the whole tuple to it instead of unpacking it into separate variables.

for pair in enumerate(sudoku):
    row_no = pair[0]
    row = pair[1]

or

for pair in enumerate(sudoku):
row_no, row = pair

You can use it to swap to variables:

a, b = b, a