Converting string to dictionary in Python
To convert a string to dictionary, we can use the built-in ast.literal_eval()
method in Python.
Here is an example:
import ast
str = "{'bat' : 'rat', 'mat' : 'kitty'}"
print(ast.literal_eval(str))
Output:
{'bat': 'rat', 'mat': 'kitty'}