Converting Strings into Python Dictionaries

To convert a string into python dictionary is not at all difficult all you have to do is to

import ast

a_string=u"{1: 'FA-1', 2: 'FA-2', 3: 'SA-1', 4: 'FA-3', 5: 'FA-4', 6: 'SA-2'}"

a_python_dictionary=ast.literal_eval(a_string)
Advertisements