# [Tutor] The Python way and two dimensional lists

Phil phillor9 at gmail.com
Tue Dec 7 20:06:51 EST 2021

```On 8/12/21 08:47, dn via Tutor wrote:
>
> row, column and a region." A "region" is what has been called a "box"

To me a box is a 3 x 3 grid of cells.

> When you separate the two ways to look at a Sudoku, life becomes a lot
> easier.self.solution[row][found_col] = set(num)mpleted this project

I pride myself in not being a rigid thinker but I suppose I am, other
wise I would have completed this project by now.

> For this reason, I would use 2D/nested dict[ionarie]s. This has the

Someone else also suggested the use of a list of dictionaries but I
didn't see the point at the time. However, now that I've used the
counter method from the collections module I can see that a dictionary
might be useful after all.

> The idea here, is to maintain a list of nine lists which represent the
> nine rows of the tableau. The second pile of nine lists represents the
> columns. Yes, when you boil-it-down, the data is repeated - each 'cell'
> appears once in a row list and again in a column list - and when a new
> value is added to the tableau, it must be added in two places. Ouch!

I'm not sure about the idea of two tables, more complications perhaps?

> So, after theorising, it was time to 'have some fun'. To compare the
> 'snake' with a 2D dict solution, I prepared some code and sufficient
> tests which progress from:
>
> An initial tableau:
>
> -------------------------------------
> |   | 2 | 7 |   | 8 | 9 | 6 |   |   |
> -------------------------------------
> |   |   |   |   |   | 1 | 7 |   | 2 |
> -------------------------------------
> | 9 |   |   |   |   |   |   |   |   |
> -------------------------------------
> |   |   |   |   | 5 |   |   |   | 7 |
> -------------------------------------
> | 1 | 7 |   |   |   |   |   | 2 | 6 |
> -------------------------------------
> | 8 |   |   |   | 4 |   |   |   |   |
> -------------------------------------
> |   |   |   |   |   |   |   |   | 4 |
> -------------------------------------
> | 2 |   | 8 | 5 |   |   |   |   |   |
> -------------------------------------
> |   |   | 1 | 8 | 6 |   | 2 | 3 |   |
> -------------------------------------

This is a rather easy puzzle to solve, my programme solved it in 3
passes. I'm not skiting, just pointing out that I have achieved something.

Are the several descriptions sufficient to start you off?

Yes, thank you and keep your code safe, I may contact you.

--

Regards,
Phil

```