I have to write a function that takes as input two numbers n and k and prints on the screen all the k-length subsets of a set created by n (order is not important), so basically a function that prints all the k-combinations of n.
For example: If n = 4 and k = 2 the initial set becomes (1,2,3,4) and it prints the following subsets:
(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)
I know that there is already a function that does that, but I have to create the function from scratch, so the use of the itertools or any other module is prohibited, and no, I can't copy the combinations function from the documentation and paste it on my code. As you may have understood, this is an assignement from my university, so I am not asking you to solve it for me and give me a code, I would like someone to explain to me how can I do it.
I know that it has to be done with a recursive function, because the number k is not known. I've also thought of 2 different solutions of how can I do this and I'm not sure if they're correct:
1st solution:
Create the powerset of the given set, and then remove all the subsets whose length is different than k.
2nd solution:
Populate a list with numbers from 1 to n^k, and then remove all the numbers that have duplicates in them. Then transform the numbers to strings and print them as sub-sets.