title: Trying to solve increment a double list in python by an index
body: <p>I am trying to solve this problem.This is leet code 1252.
  Basically you have a matrix and index. 
  Say you have a matrix</p>
  
  <pre><code>                     0 0 0
                       0 0 0
  </code></pre>
  
  <p>and you have an index</p>
  
  <pre><code>                     0   1
                       1   1
  </code></pre>
  
  <p>The left side of the index is which row value you increment by one and the right hand side is which columns value you increment by one.</p>
  
  <p>Well the you increment the 0 row by one and the 1 row by so you get</p>
  
  <pre><code>                   1  1  1 
                     1  1  1
  </code></pre>
  
  <p>and then you look at the let side of the index and that means you increment the 1 column by one and the one colums by one so you get</p>
  
  <pre><code>                      1  2  1
                        1  2  1
  
                        1   3    1
                        1   3    1
  </code></pre>
  
  <p>I tried to solve this with the following code</p>
  
  <pre><code> def matrix(n,m,index):
  
        nums=[[0]*m]*n
        print(nums)
        a=len(nums)
        b=len(nums[0])
        for i in range(a):
           c=index[i][0]
           print("the value of c is ",c)
  
           for j in range(b):
              nums[c][j]=nums[c][j]+1
       print(nums)
       for j in range(a):
           c=index[1][j]
           print(c)
           for i in range(a):
              nums[i][c]=nums[i][c]+1
       print(nums)
  
  
   index=[[0,1],[1,1]]
   n=2
   m=3
  matrix(n,m,index)
  </code></pre>
  
  <p>but I end up getting</p>
  
  <pre><code>               2   6    2
                2    6    2
  </code></pre>
  
  <p>for my input </p>
  
  <pre><code>                0    0    0
                  0    0    0
  </code></pre>
  
  <p>the weird thing is Try the same code and get the correct answer.</p>
  
  <pre><code>               def inc(nums):
                      print(nums)
                      a=len(nums)
                      b=len(nums[0])
  
                     for i in range(a):
                       c=index[i][0]
                      for j in range(b):
                           nums[c][j]=nums[c][j]+1
               print(nums)
  
                   for j in range(a):
                        c=index[1][j]
                        print(c)
                     for i in range(a):
                         nums[i][c]=nums[i][c]+1
               print(nums)
  
  
           a=[[0,0,0],[0,0,0]]
           index=[[0,1],[1,1]]
             inc(a)
  </code></pre>
  
  <p>the correct answer is</p>
  
  <pre><code>              1   3   1
                1   3   1
  </code></pre>