def-комбинация(n,k):
Код: Выделить всё
combi=[]
def backtrack(start,comb):
print(comb)
if len(comb)==k:
combi.append(comb.copy())
return
for i in range(start,n+1):
# print(i)
cur=[i]
backtrack(i+1,comb+cur)
comb.pop()
print("comb after",comb)
backtrack(1,[])
return combi
'''
Я получаю сообщение об ошибке, IndexError: pop из пустого списка
Когда я напечатал гребенку, чтобы определить ошибку, я получаю следующее:
Код: Выделить всё
1
[]
i is 1
2
[1]
i is 2
3
[1, 2]
i is 3
4
[1, 2, 3]
comb after [1]
i is 4
5
[1, 4]
comb after []
comb after []
i is 3
4
[3]
i is 4
5
[3, 4]
comb after []
Подробнее здесь: https://stackoverflow.com/questions/787 ... tify-issue