0

This question is inspired by, and is essentially a generalization of this question: From a loop index k, obtain pairs i,j with i < j?

For some n, I want a loop index k to give me all n-tuples of m numbers [0, 1, 2, ..., m-1] whose coordinates are strictly increasing, in lexicographic order.

For example, if n=2, m=3 I want to run over the variable k so that it prints out, in order (0,1), (0,2), (0,3), (1,2), (1,3), (2,3)

As another example, if n=3, m=4 I want (0,1,2), (0,1,3), (0,1,4), (0,2,3), (0,2,4), (0,3,4), (1,2,3), (1,2,4), ...(1,3,4), (2,3,4)

The problem is essentially in the post I linked to for n=2. Though, the accepted answer doesn't give the numbers in the order I wanted.

1 Answers1

0

Well I figured it out for myself. Say for n=3 It's just something like

for i in range(m-1):
for j in range(m):
    for k in range(m):
        if i<j and j<k:
            print(i,j,k) 

Then you could store the entries as list, and have the index simply run over the list.