title: Cant understand the output of the Python 2D matrix
body: <p>I am trying to print the values 1 to 9 in a Spiral Format, something like this:</p>
  
  <pre><code>[1,2,3]
  [8,9,4]
  [7,6,5]
  </code></pre>
  
  <p>However, when I try to print it through a Python script (written below), it overwrites it. I get the correct indices and the values. I just cant assign the values to the correct indices. The script is:</p>
  
  <pre><code>n = 3
  res = [[0]*n]*n
  
      count = 1
  
      def getcoord(r1,c1,r2,c2):
          for c in range(c1, c2+1):
              yield r1, c
          for r in range(r1+1, r2+1):
              yield r,c2
          if r1 &lt; r2 and c1 &lt; c2:
              for c in range(c2-1, c1-1, -1):
                  yield r2,c
              for r in range(r2-1, r1, -1):
                  yield r, c1
  
  
      r1 = 0
      r2 = n-1
      c1= 0
      c2 = n-1
      val = 1
      while r1&lt;=r2 and c1&lt;=c2:
          for r,c in getcoord(r1,c1,r2,c2):
              print(r,c)
              print("val", val)
              res[r][c] = val
              print("res", res)
              val += 1
          r1 += 1; r2 -= 1
          c1 += 1; c2 -= 1
      return res
  </code></pre>
  
  <p>When I try and debug, I get the output as follows:</p>
  
  <pre><code>(0, 0)
  ('val', 1)
  ('res', [[1, 0, 0], [1, 0, 0], [1, 0, 0]])
  (0, 1)
  ('val', 2)
  ('res', [[1, 2, 0], [1, 2, 0], [1, 2, 0]])
  (0, 2)
  ('val', 3)
  ('res', [[1, 2, 3], [1, 2, 3], [1, 2, 3]])
  (1, 2)
  ('val', 4)
  ('res', [[1, 2, 4], [1, 2, 4], [1, 2, 4]])
  (2, 2)
  ('val', 5)
  ('res', [[1, 2, 5], [1, 2, 5], [1, 2, 5]])
  (2, 1)
  ('val', 6)
  ('res', [[1, 6, 5], [1, 6, 5], [1, 6, 5]])
  (2, 0)
  ('val', 7)
  ('res', [[7, 6, 5], [7, 6, 5], [7, 6, 5]])
  (1, 0)
  ('val', 8)
  ('res', [[8, 6, 5], [8, 6, 5], [8, 6, 5]])
  (1, 1)
  ('val', 9)
  ('res', [[8, 9, 5], [8, 9, 5], [8, 9, 5]])
  </code></pre>
  
  <p>What am I missing here? Why I cant assign the correct value to the correct index, despite having them both?
  Thanks in advance!</p>