In [1]:
import ast
In [2]:
#this is a string representation of a dictionary.
string = '{"a":"apple","b":"banana","c":"chips"}'
In [3]:
#note that the key returns an error because it is not a dictionary
string['a']
In [4]:
#This evaluates the string representation into a dictionary
d = ast.literal_eval(string)
In [5]:
d
Out[5]:
In [6]:
#The key now returns the value
d['a']
Out[6]: