Let's say we need to have a board (as in a chess board) representation with tuples.
We would need the (x,y) coordinates of the square and then some extra info, for example, if there's a character of the game on it.
So I created the tuple of tuples - an empty game board like this:
n = 4
array = ()
j = 0
i = 0
for k in range(n*n):
array = array + ((i,j, 0),)
j += 1
if j%4 == 0:
j = 0
i += 1
Is this the right way to do that? Or there is a shorter way?
Then I'll be passing the array to the superclass.
I've also seen this:
super(className, self).__init__(tuple([0 for j in range(n)]), None)
Which creates a tuple of tuples or a tuple of lists? ..and then passes it into the superclass constructor.
Also, could somebody explain the 0 for j in range(n)
? (It's the 0
that bugs me. If it's a list, could it be an initialization of the list?)