views:

136

answers:

4
totalCost = problem.getCostOfActions(self.actions)
+10  A: 

Looks 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'
Space_C0wb0y
thanks...:) let me see my code again
Shilpa
can be plz tell me how to use stacktrace? where is it ? what commands I need for it?
Shilpa
@Shilpa: where did you copy the error message from? there were many more lines there, copy the whole lot.
SilentGhost
@Shilpa: The stack track is what prints when your program crashes. No commands. It's what you see.
S.Lott
oh ya....That I'll check..thanks alot
Shilpa
+1 for not being a jerk. You might mention that if you *have* to use a sequence for a `dict` key or `set` element, a tuple works.
detly
File "pacman.py", line 616, in ? runGames( **args ) File "pacman.py", line 584, in runGames game.run() File "", line 482, in run agent.registerInitialState(self.state.deepCopy()) File "/game.py", line 292, in directionToVector dx, dy = Actions._directions[direction]TypeError: list objects are unhashable
Shilpa
@Shilpa - post it in your question (you can edit questions!) and remember to mark it as code.
detly
@Shilpa: Please **UPDATE** your question with these facts. Do NOT post import information in comments. Please UPDATE your question.
S.Lott
I edited my question.please look thru it
Shilpa
@Shilpa: Now your question makes no sense at all. None. Zero.
S.Lott
Ya..i just edited my question...i dont need help in this question now..so i just deleted my code from here....
Shilpa
@Shilpa: Do you get how this site works? Other people have the same problem as you. A useless, unreadable code sample is not a question that will help others. You've made this question useless with your edit.
S.Lott
sorry....next time it will not happen..
Shilpa
+4  A: 

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.

Matt Joiner
+1  A: 

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))
>>> 
zoli2k
A: 

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

gnibbler