Screen Link: Learn data science with Python and R projects
My Code:
def find_sums_balanced(values, target_sums):
value_set = set(values)
sums = {}
for target in target_sums:
sums[target] = False
for value1 in values:
value2 = target - value1
sums[target] = value2 in value_set
return sums, value_set
What I expected to happen: I happen to expect the expected output
What actually happened: Am seeing incorrect answer.
Replace this line with the output/error
When I look at the answer I see that a if clause is being used to validate the results -
if value2 in value_set:
sums[target] = True
I expect my code to behave in the same manner. Can someone explain why this is wrong? In the page prior same code was used but it’s not working here.