Learn Algorithm Design by Building a Shortest Path Algorithm - Step 29

This step asks me to create a variable called paths and assign an empty list to each key, so I do not need to assign any value because the list must be empty: I think I am rigth.
But when I run this code on my editor I got the error: TypeError: unhashable type: ‘list’. It seems doesn’t like key:

 paths = {key:[] for key in graph.items()}

This happens because you are iterating over graph.items(). So you are assigning an unhashable object as a dictionary key.
Remember that when you iterate over a dictionary, you’ll get each key, which is exactly what you need here.

right!! I read again about the .items() method which is used to access to key-value pair within a dictionary. But in this step I only need the key and not the value therefore I solved the issue deleting .items()
Thank @Dario_DC you

1 Like