def makeGrid(rows,cols): gridRow = [] for a in range(cols): gridRow.append(0) grid = [] for b in range(rows): grid.append(gridRow) return grid # This case produces an incorrect result. Assignment to one element modifies # all elements in that column g = makeGrid(4,4) print g g[0][0] = 1 print g # This case shows the correct result without using makeGrid h = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] print '\n',h h[0][0] = 1 print h