python recursion list combinations without using generator
问题 I am learning python3. To think more about recursion, I want to implement a function comb(n, k) that returns a list consisting of all the combinations of kk elements out of a set {1,2,…,n}. I think it's not wise to use the loop since the number of the nested loop depends on k. So I consider it with recursion. I try to write the function inspired by This question while I can't get the right answer. def combinations(sub, data_set, index, still_needed): if still_needed == 0: return sub for i in