Originally Posted by
Beauxesprits13
It has been frustrating me for some time as I have been trying to iterate over x items in the zero-th nested list yet it iterates over x items in all lists.
Works for me:
Code:
>>> gap=-2
>>> matrix=[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]
>>>
>>> for x in range(1, len(matrix[0])):
... matrix[0][x] = matrix[0][x-1] + gap
...
>>> print matrix
[[0, -2, -4, -6, -8], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
But since your "matrix" has a two dimensions, the output should have two levels of brackets, so I suspect that you code is not really doing "print matrix" and prints the first line repeatedly.
Bookmarks