title: Generalising different for-loop method in Python
body: <p>I have this following code where I am trying to form an array 'opt'. Here, I am taking three possible values of 'pos_set' = [1, 2, 3] and in a similar manner, I can extend this. But, I just want a generalized code for any possible integer value of pos_set. </p>
  
  <pre><code>    opt = []
      if pos_set == 1:
          for j in range(1, n):
              opt.append([j])
      elif pos_set == 2:
          for j in range(1, n):
              for k in range(j+1, n):
                  opt.append([j, k])
      elif pos_set == 3:
          for j in range(1, n):
              for k in range(j+1, n):
                  for l in range(k+1, n):
                      opt.append([j, k, l])
  </code></pre>
  
  <p>For more clarity, I am doing this with the objective of collecting all possibilities if you roll an n-sided die and keep doing this as long as you keep rolling larger values.</p>
  
  <p>For instance, if you roll a sequence 1-2-6-4, in this case after getting a 4 following a larger no. 6, you stop rolling. Similarly, if you roll a sequence 1-2-6-6, in this case you get a repeated 6 so you stop because it is not larger than your previous roll. I am considering cases before the smaller or same number occurs i.e., [1, 2, 6] in both cases.</p>
  
  <p>If you guys can help me, I would be grateful.</p>