title: Diagonals in a non-square matrix - python
body: <p>In previous question I found a way to get all the diagonals from a sqare matrix. This is my code:</p>
  
  <pre><code>diags=[[s[y-x][x] for x in range(n) if 0&lt;=y-x&lt;n] for y in range(2*n-1)] 
  </code></pre>
  
  <p>For example, I have this matrix:</p>
  
  <pre><code>m=[[V,A,T],[D,I,S],[O,I,M],[F,U,A]]
  </code></pre>
  
  <p>This is the output I want:</p>
  
  <pre><code>[[V],[D,A],[O,I,T],[F,I,S],[U,M],[A]]
  </code></pre>
  
  <p>I already know how to get the diagonals in forward and reverse directions.<br>
  The problem is that this code only works for sqare matrix, but now I need to find all the diagonals in a non-square matrix. <br>I think the problem is with this part of the code:</p>
  
  <pre><code>for y in range(2*n-1)
  </code></pre>
  
  <p>My question is: Is there a way to define diagonals for a non-square matrix? And if there has, would someone help me?<br>
  I found nothing that would help me in other questions.<br>
  P.S: I'm not allowed to use numpy.<br>
  Any form of help, hint, advice would be appreciated.<br></p>