Skip to content

Instantly share code, notes, and snippets.

@jstitch
Created March 15, 2012 20:35
Show Gist options
  • Save jstitch/2046727 to your computer and use it in GitHub Desktop.
Save jstitch/2046727 to your computer and use it in GitHub Desktop.
Convert a string representing a dictionary into an actual dictionary
st = "{'a':'b','c':'d'}"
dc = dict([[g.replace("'","").replace('"',"") for g in f.split(":")] for f in st[1:-1].split(",")])
st2 = "'a':'b','c':'d'"
dc = dict([[g.replace("'","").replace('"',"") for g in f.split(":")] for f in st2[1:-1].split(",")])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment