I write an algorithm that sums up two numbers in a list so that it is equal to 15 or 13 or 7 then deletes those numbers from the original list and then repeats the process. Until there are no more or fewer numbers in the starting list. There is always the following problem: IndexError: list assignment index out of range.
I tried using dictionaries or finding another algorithm, because what I'm doing is a bit of brute force. But in vain.
number = [10,5,14,1,12,2,7,6,10,3,8]
case1=15
case2=13
lc1i = []
lc1j = []
lc2i = []
lc2j = []
def seperate(number,case1,case2):
for i in number:
for j in number:
if i+j == case1:
lc1i.append(i)
del number[i]
lc1j.append(j)
del number[j]
elif i+j == case2:
lc2i.append(i)
del number[i]
lc2j.append(j)
del number[j]
print(number)
seperate(number,case1,case2)
I expect at the end to have two differents dictionaries: the first one has all pairs which together make 15 and the other all pairs which make 13. but I have this message :IndexError: list assignment index out of range