totalCost = problem.getCostOfActions(self.actions)
views:
136answers:
4Looks like you are trying to use a list as key in a dictionary or something like that. Lists are not hashable, and so they cannot be used as dictionary keys or in sets.
On another note, python gives you a stacktrace when such an error happens, and that includes file-names and line-numbers. You should be able to track down the offending code with that.
Edit About stacktraces:
cat > script.py
foo = [1,2,3]
bar = {}
bar[foo] = "Boom"
print "Never happens"
python script.py
Traceback (most recent call last):
File "script.py", line 3, in <module> // this is the file and the line-number
bar[foo] = "Boom"
TypeError: unhashable type: 'list'
You've probably attempted to use mutable objects such as lists, as the key for a dictionary, or as a member of a set. Mutable items cannot be tracked for such uses efficiently and predictably so they do not provide the hash special attribute.
The error is produced when an unhashable type is added to sets.
>>> s=set((1,2))
>>> a.add([3,4])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
I think this may be also your case. Use tuple instead of list:
>> a.add((3,4))
>>>
Maybe the line should be like this instead
totalCost = sum(map(problem.getCostOfActions,self.actions))
or if you prefer a generator expression
totalCost = sum(problem.getCostOfActions(action) for action in self.actions)
Since I can't see your code, I assumed that problem.getCostOfActions()
returns the cost of a single action, as that might cause the error you are getting if self.actions
is a list
Alternatively you could fix the function problem.getCostOfActions()
so that it returns the total cost of a list of actions as the name suggests.
Consider adding the body of this function to your question if you want help fixing it