+ 1
Saving the results of the recursion.
The task is as follows. It is necessary to iterate over all combinations of numbers from zero to "set - 1" (set = 4, then 0,1,2,3). The length of the combination "length" (If length = 3, there can be such combinations - 000,010,111). The task is trivial, but I have no idea how to keep all these combinations in the list, since the combination ends in the base case. https://code.sololearn.com/cqsS3oVcQ072/?ref=app
2 Respuestas
+ 2
Python
def countdown():
i=5
while i > 0:
yield i
i -= 1
l=[]
for i in countdown():
l.append(i)
print(l)
+ 1
I managed to figure out the problem. But thanks anyway.
def pr(set,length,list=[],s=[]):
if length==0:
j=list[:]
s.append(j)
return
for i in range(set):
list.append(i)
pr(set,length-1,list,s)
list.pop()
return s
print(pr(2,3))