Asking "is hashable" about a Python value
<p>I am interested in taking an arbitrary dict and copying it into a new dict, mutating it along the way.</p>

<p>One mutation I would like to do is swap keys and value. Unfortunately, some values are dicts in their own right. However, this generates a "unhashable type: 'dict'" error. I don't really mind just stringifying the value and giving it the key. But, I'd like to be able to do something like this:</p>

<pre><code>for key in olddict:
  if hashable(olddict[key]):
    newdict[olddict[key]] = key
  else
    newdict[str(olddict[key])] = key
</code></pre>

<p>Is there a clean way to do this that <em>doesn't</em> involve trapping an exception and parsing the message string for "unhashable type" ?</p>
