I am trying to initialize a list, but then I have to change each cell in said list. I did:
matrix = [[[0] * len(t[0])] * len(t[0])]
But when trying to change one cell it changes the entire column of the matrix. Why is this?
I am trying to initialize a list, but then I have to change each cell in said list. I did:
matrix = [[[0] * len(t[0])] * len(t[0])]
But when trying to change one cell it changes the entire column of the matrix. Why is this?
Yes the problem is that you are copying references and not creating new objects, to solve that you can do something like this:
matrix = [[0 for _ in xrange(len(t[0]))] for _ in range(len(t[0]))]