[Tutor] The Python way and two dimensional lists

Phil phillor9 at gmail.com
Mon Nov 22 15:05:41 EST 2021


> I think you actually wanted:
>
> solution[0] = [{7,3}, {5}, {4,8,6}, {7,8}, {1}, {9,3}, {7,9}, {4,6,3},
> {2}]
>
Thank you once again Alan for your helpful advice.

Once I'd given myself a chance to give this some thought I realised my 
mistake. I'd been fixated on doing things the Python way.


> One thing you might consider is using the Python
> interactive prompt

I use VS Code for my main projects and IDLE for simple tasks like this 
one and often, maybe not often enough, use the interactive prompt to 
test ideas.


> Another option that could work here, and is often
> used in professional code, is to just do the initialisation
> in a hard coded list format:

That's the way I had originally set up the grid. I thought I was acting 
like the big boys by using list comprehension.


> Obviously this technique isn't effective with huge data
> sets, but for this purpose should work well and may help
> you visualize things better.

I use grids and look-up tables in many of my projects and hard coding 
them ensures that they are the right way around instead of sideways. 
I've always found the list comprehension method anything but comprehensible.

-- 

Regards,
Phil



More information about the Tutor mailing list