grid = [] # grid will be a list of lists, i.e. list of rows """ if we create one row outside the loop and append it 3 times then setting [0][2] will actually set [n][2] which is column 2 in every row duplicate references """ for y in range(3): # create 3 rows row = [0] *4 # create a new row each time with 4 columns grid.append(row) # method to add an element to the list print grid print "------------\n" grid[0][2] = 5 # row 0, column 2; index order from right to left # print grid for y in grid: # y is a list # t = type(y) # print t print y print "------------\n" # list comprehension, can run twice as fast # somewhat inverted syntax in that expression precedes iterator d = [ [9]*4 for y in range(3) ] print d print "------------\n" d[0][3] = 1 for row in d: print row print "------------\n" # 3-D array: 2 planes with 3 rows of 4 columns # only do one [n]*m otherwise it will duplicate references to a list d = [ [[9]*4 for y in range(3)] for z in range(2) ] print d print "------------\n" d[0][2][1] = 1 # plane 0, row 2, column 1 print d print "------------\n" for plane in d: for row in plane: print row print "------------"