title: What is the best way to write a multiple nested for loops in Python
body: <p>I am working on a code where I need to use a nested loop as follows:</p>
  
  <pre><code>for r in range(m):
     for s in range(r+1, m):
        for t in range(s+1, m):
           for u in range(t+1, m):
              for v in range(u+1, m):
                    arr.append([r,s,t,u,v])
  </code></pre>
  
  <p>But this traditional nested loops look pretty ugly. Is there a way to perform the same operation with less lines? </p>
  
  <p>I looked at itertools.product but I was not able to get what I want since all start/end indices of my loops depends on the previous level.</p>