you just created 3 rows with the same reference with a=x*[x*[0]]
. x*[0]
is built once, and propagated on all rows by the outer multiply operator.
Changing a row changes all the rows. Note that it can be useful (but not there obviously)
Do that instead (using a list comprehension):
a=[x*[0] for _ in range(x)]
so references of each row are separated