[Tutor] Creating a two dimension set
Phil
phillor9 at gmail.com
Sun Oct 31 01:56:53 EDT 2021
As an example, if I wanted to create a two dimension list I would write:
num_rows = 9
num_cols = 9
self.solution = [[None] * num_cols for _ in range(num_rows)]
In my current creation I need a two dimension set and so I have used,
again for example:
result = set(self.solution[row][col]) - 3
However, my code has grown and I find that I'm making mistakes and it
would be much simpler if I'd created a two dimension set in the first
place rather that converting the list to a set every time I need to
access it.
I could, I suppose, use two for loops to create and initialise the set
but there must be a simpler and less tedious way.
I have very poor Internet access at the moment and searching for an
answer hasn't been fruitful due to frequent disconnections. All that
I've gained is a headache.
--
Regards,
Phil
More information about the Tutor
mailing list