I have a problem with creating objects, where 2D array has variable length. I keep getting error
self.state[i] = listt[i]
IndexError: list assignment index out of range
If i try to create object with array with 2 rows and 3 columns, it works. If i try create an object with 3 rows and 3 columns it fails with the error.
class node:
def __init__(self, m, n, listt=None):
self.not_in_place = -1
self.m = m
self.n = n
self.state = [[m],[n]]
if listt is not None:
for i in range(self.m):
self.state[i] = listt[i]
start = [[0,1,2],[3,4,5],[6,7,8]]
node(3, 3, start) # doesn't work
start_2 = [[0,1,2],[3,4,5]]
node(2, 3, start_2) # work
What am i doing wrong ?