(Dec-17-2020, 06:01 PM)muzikman Wrote: Actually, this won't work with x + anything greater than 1. So, I should have just hard coded the numbers in there, As such:Nonsense
This will work for any number of lists, as long as you supply them as arguments to itertools.product
(Dec-17-2020, 05:57 PM)buran Wrote:from itertools import product list1 = [30, 50, 110, 40, 15, 75] list2 = [10, 60, 20, 50] sum_list = [item for item in product(list1, list2) if sum(item) > 100] for item in sum_list: print(*item, sep=' ')
from itertools import product list1 = [30, 50, 110, 40, 15, 75] list2 = [10, 60, 20, 50] list3 = [59, 68, 20, 78, 98] sum_list = [item for item in product(list1, list2, list3) if sum(item) > 100] for item in sum_list: print(*item, sep=' ')
Output:30 10 68
30 10 78
30 10 98
30 60 59
30 60 68
30 60 20
30 60 78
30 60 98
30 20 59
30 20 68
30 20 78
30 20 98
30 50 59
30 50 68
30 50 78
30 50 98
50 10 59
50 10 68
50 10 78
50 10 98
50 60 59
50 60 68
50 60 20
50 60 78
50 60 98
50 20 59
50 20 68
50 20 78
50 20 98
50 50 59
50 50 68
50 50 20
50 50 78
50 50 98
110 10 59
110 10 68
110 10 20
110 10 78
110 10 98
110 60 59
110 60 68
110 60 20
110 60 78
110 60 98
110 20 59
110 20 68
110 20 20
110 20 78
110 20 98
110 50 59
110 50 68
110 50 20
110 50 78
110 50 98
40 10 59
40 10 68
40 10 78
40 10 98
40 60 59
40 60 68
40 60 20
40 60 78
40 60 98
40 20 59
40 20 68
40 20 78
40 20 98
40 50 59
40 50 68
40 50 20
40 50 78
40 50 98
15 10 78
15 10 98
15 60 59
15 60 68
15 60 78
15 60 98
15 20 68
15 20 78
15 20 98
15 50 59
15 50 68
15 50 78
15 50 98
75 10 59
75 10 68
75 10 20
75 10 78
75 10 98
75 60 59
75 60 68
75 60 20
75 60 78
75 60 98
75 20 59
75 20 68
75 20 20
75 20 78
75 20 98
75 50 59
75 50 68
75 50 20
75 50 78
75 50 98
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs