convert string to dictionary in python

Cool trick to convert strings into dictionary object in Python Programming

Method 1: Using ast.literal_eval

## Example

import ast
strr = "{'a': 1, 'b': 2, 'c': 3}"
strr_dict=ast.literal_eval(strr)

Method 2: Using json
## Example

1 comment: