I found a code that recursively returns all combination of a list of 1 to n numbers with length k
def choose_iter(elements, length):
for i in range(len(elements)):
if length == 1:
yield (elements[i],)
else:
for next in choose_iter(elements[i+1:len(elements)], length-1):
yield (elements[i],) + next
def choose(l, k):
return list(choose_iter(l, k))
this will return what I need but can I modify this so that I dont have to use the yield function? I haven't studied yield yet and I don't want to confuse myself with this.