If you want to do that you need to create a 'row' in the first loop to add into the main grid
array. You then append cells to this row, and append the whole row to the grid.
Like so:
def insertion (r, c, grid):
cellGrid = []
for x in range(0, r):
row = []
for y in range(0, c):
if (grid[x][y] == '%'):
what = 0
cost = 100000000
elif(grid[x][y] == '-'):
what = 1
cost = 1
elif (grid[x][y] == '.'):
what = 2
cost = 0
else:
what = 3
row.append(Cell(what, cost))
cellGrid.append(row)
return cellGrid