Subscribe:

Monday, 7 April 2014

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

0 comments:

Post a Comment

Pc tricks
Powered by Conduit Mobile