Q:

How to reference a specific element in a 2D array python

I'm trying to create a 2d grid to simulate a world, and I've decided to use a 2d array, with one element per grid square. It is 40x40 and I used this to set up the grid:
gridy = ["grass" for i in range(0,40)]
gridx = [gridy for i in range(0,40)]

The problem is I don't know how to reference/ change a single element from this array, (e.g. the grid tile with coordinates (5,5))
This is what I've used so far:
gridx[5][5] = "water"

The program should place water in random places, and a piece of food in a random place.
However, when I run the program the grid looks like this:
broken grid
At the moment you can't see the whole grid because it's too big for the window (ill fix later) but you get the idea.
It seems that instead of taking each tile as one element, it's taking an entire row as an element.
How can I reference just one single tile?
Thanks

A:

I'd recommend to check out numpy :) 
It's fast and you can easily do 2d-array manipulations. ( and by that I mean much more even than assigning values as below, which is of course also easily possible with lists) 
import numpy as np
x = np.zeros((40, 40)) # create array of size 40 x 40 
x[5][5] = 1

where 0 stands for grass and 1 for water. You can also change the type of the array to be able to fill it with strings. 
That being said, the approach without numpy should also work. 
Indeed your commands are perfectly fine. 
gridy = ["grass" for i in range(40)] 
gridx = [gridy for i in range(0,40)]
gridx[5][5] = "water" # works :) 
print(gridx[5][5]) # >> prints: "water"

On a side note, it's worth noting that range(0, 40) is the same as range(40)

