Having the following code:
def choose_sets(lst,k):
if k == 0:
return [[]]
if len(lst) == k:
return [lst]
else:
return choose_sets(lst[1:],k)+[[lst[0]]+i for i in choose_sets(lst[1:],k-1)]
How does i for i in choose_sets(lst[1:],k-1) work? Is it possible to give up on the loop and instead to write this?
+[[lst[0]]+choose_sets(lst[1:],k-1)]
this function returns list that contains all the different lists at length K that can be created out of the original list's members (the order isn't important)