Reputation: 17
I am getting
TypeError: 'NoneType' object is not iterable
when I try to find the sum of a list.
Where the problem occurs:
if(sum(self._candidates) + self._allCandidates[self._depth]._weight > 20):
self._left = Node(self._candidates, self._depth + 1, self._allCandidates)
else:
self._left = Node(self._candidates.append(self._allCandidates[self._depth]), self._depth + 1, self._allCandidates)
Node definition:
def __init__(self, candidates = [], depth = -1, allCandidates = []):
self._candidates = candidates
self._depth = depth
self._allCandidates = allCandidates
Thanks for any help on this matter.
Upvotes: 0
Views: 1338
Reputation: 48028
This is wrong:
Node(self._candidates.append(self._allCandidates[self._depth])
The return value from .append
is None
, hence the error.
Upvotes: 5