You are assigning a new value to the name x but that does not change the contents of row or data. After changing x, you need to assign row[j] = x or data[i][j] = x for the appropriate column index j (and row index i). See also python 3: lists dont change their values