EDIT: Solved
I'm having an issue with my code, and Google seems to think it's a simple fix, but I've been trying the fixes and they aren't working. I don't understand why it doesn't work. (The goal of the code is to loop through grid, printing each string value in the list, then going to the next line and printing each value in the next list, etc. in order to form a picture.)
I'm having an issue with my code, and Google seems to think it's a simple fix, but I've been trying the fixes and they aren't working. I don't understand why it doesn't work. (The goal of the code is to loop through grid, printing each string value in the list, then going to the next line and printing each value in the next list, etc. in order to form a picture.)
grid = [['.', '.', '.', '.', '.', '.'], ['.', 'O', 'O', '.', '.', '.'], ['O', 'O', 'O', 'O', '.', '.'], ['O', 'O', 'O', 'O', 'O', '.'], ['.', 'O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O', '.'], ['O', 'O', 'O', 'O', '.', '.'], ['.', 'O', 'O', '.', '.', '.'], ['.', '.', '.', '.', '.', '.']] for y in grid: for x in grid[y]: print(grid[x][y], end = '') print('')This gives the error "list indices must be integers or slices, not list". But I've tried other things such as:
for x in len(grid[y]): for x in int(grid[y]): for x in int(len(grid[y]): for x in grid[int(y)]):I really don't know what else to do. I must be missing something simple. I realize I could easily just write:
for x in grid[9]:but this ruins scalability, and I still run into the same error on the line:
print(grid[x][y])