I am trying this simple function that switches the keys and values for a given dictionary:
def reverse_dict(d):
return {y:x for x,y in d.items()}
Works fine if the values are immutable, however if one of the values is a list I get the following error:
TypeError: unhashable type: 'list'
Why does the value have to be immutable for this function to work? I'm interested in what happens in terms of python's memory model.