Reputation: 111
Right now, I am trying to include only two arguments and I have been using the code below.
for i in d2:
for j in D1:
x[j] = d2[i]-D1[j]
for k in D1:
if (x[j] == D1[k]):
break
print d2[i] = D1[j] + x[j]
ERROR
When I tried to run the code, I got this error:
Traceback (most recent call last):
line 11, in <module>
x[j] = d2[i]-D1[j]
IndexError: list index out of range
Upvotes: 1
Views: 48
Reputation: 30288
Checking the sum of all pairs are in another list (off the top of my head):
import itertools as it
D1 = ...
D2 = ...
def my_check(list1, list2):
for x, y in it.combinations(list1, 2):
if x+y in list2:
yield x, y
for x, y in my_check(D1, D2):
print("{} = {} + {}".format(x+y, x, y))
Upvotes: 1