Answer the question
In order to leave comments, you need to log in
How can one iterate over all possible values of a list with restrictions?
Hello, there is a code with conditions for the list, tell me how you can organize a sequential enumeration of all possible values of the list with sequential output.
pr1=[2,3,1,2,4]
pr2=[3,4,10,11,12]
n=5
xlst=[0] * n
for i in range(len(xlst)):
if (n-sum(xlst[:i]))>0:
xn=n-sum(xlst[:i])
else:
xn=0
xlst[i]=min(xn, pr1[i], pr2[i]-sum(xlst[:i]))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question