title: Transforming the string representation of a dictionary into a real dictionary
body: <p>I am working on an image processing script. I need to let the user specify how to remap some classes in an image via a text file. The syntax in this file should be simple and self-evident. What I thought of doing is to get the user to write the string version of a dictionary:</p>
  
  <pre><code>125:126, 126:126, 127:128, 128:128
  </code></pre>
  
  <p>and then transform it into a real dictionary (this is the missing link):</p>
  
  <pre><code>a = {125:126, 126:126, 127:128, 128:128}
  </code></pre>
  
  <p>The remapping of the classes of the image would then be done like this:</p>
  
  <pre><code>u, indices = numpy.unique(image, return_inverse=True)
  for i in range(0, len(u)):
      u[i] = a[u[i]]
  updatedimage = u[indices]
  updatedimage = numpy.resize(updatedimage, (height, width)) #Resize to original dims
  </code></pre>
  
  <p>Is there a simple way to do this transformation from the "string version" to a real dictionary? Can you think of an easier/alternative one-line syntax that the user could use?</p>