Нужно найти в списке числа из которых получается k
spis =
k = 5
newmas =
for i in spis:
c = int(i)
for j in range(i + 1, spis):
if spis + spis == k:
newmas.append(spis + spis)
print(newmas)
import itertools num = 5 my_list = [1, 2, 3, 1, 1, 4, 2, 1, 1] out = [] for i in range(2, len(my_list)+1): for combo in itertools.combinations(my_list, i): combo = sorted(combo) if sum(combo) == num: if combo not in out: out.append(combo) for i in out: print(i)
[1, 4]
[2, 3]
[1, 2, 2]
[1, 1, 3]
[1, 1, 1, 2]
[1, 1, 1, 1, 1]
Process finished with exit code 0