So I have a function findsum(s,g) and I want to find whether elements in
s:list
can be the sum of any numbers in
g: list
or not... so for instance, if
s = [0,2,3,4,5]
,
g = [1,2,3]
,
the output should return
[False, True, True, True, True]
...
Explaination:
So 0 is false because nothing in g equals to or adds up to 0
2 is true because g contains a 2
3 is true because 2 and 1 in g adds up to 3
4 is true because if we add 2 to itself, 4 is the result
5 is also true because if we add 2 and 3 from g, we get 5
What I have tried:
def findsum(s,g):
for f in g:
for x in s:
if sum (x) == f:
return True
else:
return False