This will be the code of combination
using recursion, and this will give you all the subsets of given list and the subsets of desired length.
l1 = [1, 2, 3]
s = 2
unique = []
def combination(set):
if set == []:
return [[]]
sub = combination(set[1:])
# This will give you all the subsets of given list and This is also the return variable of the function.
all_combination = (sub + [[set[0]] + x for x in sub])
########################################################
# This for loop will give you a subsets of desire length.
for i in range(len(all_combination)):
if int(len(all_combination[i])) == s and all_combination[i] not in unique:
unique.append(all_combination[i])
#########################################################
return all_combination
print(combination(l1))
print(unique)
