Dec-17-2020, 05:50 PM
First of all, there's no need to explicitly count how many items there are and index into the list. Once you have your sum_list, you can just loop over the items to print them. (I'll show that below).
The other thing is if you need all the matchups from two lists, there's a function called product() that will generate them. Combining the two, you could do the above as:
The other thing is if you need all the matchups from two lists, there's a function called product() that will generate them. Combining the two, you could do the above as:
from itertools import product list1 = [30, 50, 110, 40, 15, 75] list2 = [10, 60, 20, 50] sum_list = [p for p in product(list1, list2) if sum(p) > 100] for x, y in sum_list: print(x, y) # or could do instead... #for t in sum_list: # print(t[0], t[1])