title: how to change values of a list based on index of another list in python?
body: <p>I have the following list </p>
  
  <pre><code>I=[[[0, 0, 0], [0, 0, 0], [0, 0, 0]],
     [[0, 0, 0], [0, 0, 0], [0, 0, 0]],
     [[0, 0, 0], [0, 0, 0], [0, 0, 0]],
     [[0, 0, 0], [0, 0, 0], [0, 0, 0]],
     [[0, 0, 0], [0, 0, 0], [0, 0, 0]]]
  </code></pre>
  
  <p>I would like to replace some elements of 0 by 1 in list I based on index of nother list S</p>
  
  <pre><code>S=[2,2,1]
  
  </code></pre>
  
  <p>Note that :
  The first element in list S corresponds to the first column in the list I, 
  2nd  element in list S corresponds to the 2nd column in the list I
  3rd element in list S corresponds to the 3rd column in the list I</p>
  
  <p>the output like this </p>
  
  <pre><code>IS=[[[1, 0, 0], [0, 0, 0], [0, 0, 0]],  
      [[0, 1, 0], [0, 0, 0], [0, 0, 0]],     
      [[0, 0, 0], [1, 0, 0], [0, 0, 0]],
      [[0, 0, 0], [0, 1, 0], [0, 0, 0]],     
      [[0, 0, 0], [0, 0, 0], [1, 0, 0]]]
  </code></pre>
  
  <p>The output i want to get is as follows:
   starting by colmn1 which corresponds to the first element in list S,  since S[0]=2 , we access the first two rows in colmn1 of the list I and replace 0 with 1  diagonally.
  then we get</p>
  
  <pre><code> colmn1      colmn2      colmn3
  [[**1, 0, 0]**, [0, 0, 0], [0, 0, 0]], row 1 
  [**[0, 1, 0]**, [0, 0, 0], [0, 0, 0]], row 2
  </code></pre>
  
  <p>Then move to the second element of S which corresponds the colmn2 in list I, since S[1]= 2  then we access the next two rows in colmn2 and replace the 0 elements diagonally in these next two rows.</p>
  
  <pre><code> colmn1      colmn2      colmn3
  [[1, 0, 0], [0, 0, 0], [0, 0, 0]], row 1 
  [[0, 1, 0], [0, 0, 0], [0, 0, 0]], row 2
  [[0, 0, 0], **[1, 0, 0]**, [0, 0, 0]], row 3
  [[0, 0, 0], **[0, 1, 0]**, [0, 0, 0]], row 4
  </code></pre>
  
  <p>finally, go to last element in S ( corresponding last colmn in list I), since we have S[2]=1 so that  we access the next row and replace 0 with 1 in the diagonal direction to get</p>
  
  <pre><code> colmn1      colmn2      colmn3
  [[1, 0, 0], [0, 0, 0], [0, 0, 0]], row 1 
  [[0, 1, 0], [0, 0, 0], [0, 0, 0]], row 2
  [[0, 0, 0], [1, 0, 0], [0, 0, 0]], row 3
  [[0, 0, 0], [0, 1, 0], [0, 0, 0]], row 4 
  [[0, 0, 0], [0, 0, 0], **[1, 0, 0]**], row 5
  </code></pre>
  
  <p>I hope the explanation is clear  </p>