Created
March 15, 2012 20:35
-
-
Save jstitch/2046727 to your computer and use it in GitHub Desktop.
Convert a string representing a dictionary into an actual dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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