How to write all $r$-tuples with a certain property in a list
There are many ways to compute all $k$-tuples of elements in a given list $L$. One way is to use recursion and the analogue of Pascal's identity $$\binom{n}{k}=\binom{n-1}{k}+\binom{n-1}{k-1}. $$ We can interpret this identity as follows. Write $L=x, L'$, where $x$ is the first element and $L'$ is the rest of the list. A $k$-tuple of $L$ is either a $k$-tuple of $L'$, or $x$ along with a $k-1$-tuple of $L'$. I'll let you figure out how to turn this into a solution for your problem. 

Using the same idea, you can also write a function that given $m$ outputs the $m$th $k$-tuple of $L$, in lexicographic order. You can even decode such a tuple back to its index in this order. 

If you don't like recursion, you can also try an iterative approach. The idea is to start with the tuple $0,1,\ldots, k-1$, and keep incrementing the tuple. To increment the tuple, start by incrementing the last position. If it's now $n$, we backtrack and increment the previous position. If that one is now $n-1$, we backtrack once more, and so on. Eventually, unless we were at the last tuple, we well have incremented some position successfully, say to the value $m$. The following position (if any) we set to $m+1$, the one after it (if any) to $m+2$, and so on. I'll let you figure out how to implement this idea. 

Both approaches can be implemented so that they produce the same, lexicographic, order. There are probably other, trickier approaches, that rely on applying an intricate sequence of transpositions on the list $0,1,\ldots, n-1$, but the ones I described are general approaches applicable in many other situations. For the more magical ones, check Knuth's new volumes-in-preparation of TAOCP.