How to control the number of layer in nested for-loop in python? : <p>Given a list like <code>alist = [1, 3, 2, 20, 10, 13]</code>, I wanna write a function <code>find_group_f</code>, which can generate all possible combination of elements in <code>alist</code> and meanwhile I can dynamically control the number <code>k</code> of element in each group. For instance, if the number <code>k</code> is <code>2</code>, the function is equal to:</p>

<pre><code>for e1 in alist:
    for e2 in alist[alist.index(e1)+1:]:
        print (e1, e2)
</code></pre>

<p>While the number <code>k</code> is 3, it would be like:</p>

<pre><code>for e1 in alist:
    for e2 in alist[alist.index(e1)+1:]:
        for e3 in alist[alist.index(e2)+1:]:
            print (e1, e2, e3)
</code></pre>

<p>I wonder how can I implement like this? Thanks in advance!</p>
