title: Creating list of lists containing objects in python
body: <p>I am trying to put a custom object into a 2d list and I'm getting very confused. 
  Here's what I have:</p>
  
  <p>Here's the cell class:</p>
  
  <pre><code>class Cell(object):
      def __init__(self, what, cost):
          self.what = what
          self.parentx = -1
          self.parenty = -1
          self.f = 0
          self.g = 0
          self.h = 0
          self.cost = cost
  </code></pre>
  
  <p>and my insertion object (where I take a grid/ maze and put the data into objects):</p>
  
  <pre><code>def insertion (r, c, grid):
      cellGrid = []
      for x in range(0, r):
          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
              cellGrid.append(Cell(what, cost))
      return cellGrid
  </code></pre>
  
  <p>This does work, but what I really want is cellGrid to be a 2d list, just like grid, except that it will contain cell objects intstead of a string.  I would like to be able to acceess it as <code>cellGrid[0][0].what</code> for example.  How should I accomplish this?</p>