Cool trick to convert strings into dictionary object in Python Programming
## Example
import ast
Method 1: Using ast.literal_eval
import ast
strr = "{'a': 1, 'b': 2, 'c': 3}"
strr_dict=ast.literal_eval(strr)
Method 2: Using json
## Example
Check here http://docs.python.org/library/json.html
0 comments:
Post a Comment