[Tutor] The Python way and two dimensional lists

Phil phillor9 at gmail.com
Mon Nov 22 15:19:37 EST 2021


> 	Create 9x9 of empty sets
>
>>>> solution = [ [ set() for _ in range(9)] for _ in range(9)]
>>>> solution

Thanks Dennis. I had originally used 'None' where you have 'set()'.


> 	Bind 9 element tuple to the 9 spaces in the first "row"
>
>>>> 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.

-- 

Regards,
Phil



More information about the Tutor mailing list