[Tutor] The Python way and two dimensional lists

Alan Gauld alan.gauld at yahoo.co.uk
Mon Nov 22 18:59:58 EST 2021


On 22/11/2021 20:19, Phil wrote:

>>>>> solution[0][0:9] = {7,3}, {5}, {4,8,6}, {7,8}, {1}, {9,3}, {7,9}, {4,6,3}, {2}
>>>>> solution
> 
> I haven't seen slicing used that way before. I'll keep it in mind.

slice assignments are powerful but very easy to get wrong
(off by one errors etc). Even Denis got it wrong first time
round!

That's why I prefer the more direct approach:

solution[0] = [{7,3},{5},{4,8,6},{7,8},{1},{9,3},{7,9},{4,6,3},{2}]

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list