title: Python IndexError: list assignment index out of range
body: <p>Can anyone point me to what's wrong?</p>
  
  <p>I got stuck on <code>newGrid.setValue(n[k][0], n[k][1], List[k])</code> trying to feed the values of each x/y of each coord into a different function, which takes three arguments, x y and value. Value is what is printed in a position on a grid, x &amp; y are the coordinates.</p>
  
  <blockquote>
  <pre><code>self.listOfRows[x - 1][y - 1] = value 
  </code></pre>
    
    <p>IndexError: list assignment index out of range</p>
  </blockquote>
  
  <pre><code>def gridMileage(List):
      x = []
      y = []
      n = []
      k = 0
      best = 0
      while len(List) &gt; 0:
          for i in range(len(List)):
              x = List[i][0]
              y = List[i][1]
              n.append([x,y])
          if x &gt; best:
              best = x
          elif y &gt; best:
              best = y
          newGrid = Grid(best)
          while k &lt; 2:
              newGrid.setValue(n[k][0], n[k][1], List[k])
              k = k + 1
          del List[0]
          del List[1]
          del n[0]
          del n[1]
          newGrid.setValue(n[0], n[0] + 1, math.sqrt((n[0][0] - n[1][0])**2 + (n[0][1] - n[1][1])**2))
          newGrid.setValue(n[1] + 1, n[1], math.sqrt((n[1][0] - n[0][0])**2 + (n[1][1] - n[0][1])**2))
          z = len(newGrid.listOfRows)
          while z &gt; 0:
              print(newGrid.listOfRows[z - 1])
              z = z - 1
  
  class Grid:
      def __init__(self, n):
          self.listOfRows = []
          for i in range(n):
              row = []
              for j in range(n):
                  row.append('*')
              self.listOfRows.append(row)
  
      def setValue (self, x, y, value):
          self.listOfRows[x - 1][y - 1] = value
  </code></pre>