title: Initializing a two-dimensional array in Python?
body: <p>I wonder What is the difference between this two different method of 2D matrix initialization in python. </p>
  
  <pre><code>    m =[]
      K = []
      for x in range(0,W+1):
          m.append(0)
      for x in range(0,n+1):
          K.append(m)
  </code></pre>
  
  <p>and </p>
  
  <pre><code>    l = []
      for j in range(0,n+1):
          l.append([])
          for i in range(0,W+1):
              l[j].append(0))
  </code></pre>
  
  <p>when I tried to print l and K the both gave the same answer but when I tried to implement it in code the output of program changed.</p>
  
  <p>the earlier one(K) gave an incorrect answer but later one(l) when implemented in the program gave a correct answer.</p>