Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

Python program to find unique combinations in a list with target sums

$
0
0

"I need assistance in writing a Python program that takes an input list (input_set) and a list of target sums (target_sums). The goal is to find unique combinations of elements from input_set that add up to each target sum. The resulting combinations should be stored in an output list (output_set), and duplicates within the combinations are not allowed.

Input example 1

input_set = \[10, 2, 20, 40, 2, 7\]target_sums = \[37, 42, 2\] 

Output example 1

\[\[10, 20, 7\], \[2, 40\], \[2\]\] 

Input example 2

input_set = \[10, 5, 20, 40, 2, 7\] target_sums = \[37, 42, 5\] 

Output example 2

\[\[10, 20, 7\], \[2, 40\], \[5\]\] 

Input example 3

input_set_3 = \[10, 20, 30, 40, 20, 40, 60, 80, 300\] target_sums_3 = \[100, 200, 300\] 

Output example 3

\[\[10, 20, 30, 40\], \[20, 40, 60, 80\], \[300\]\]

Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>