Bruce
0
Q:

convert string representation of dict to dict python

# Python3 code to demonstrate 
# convert dictionary string to dictionary 
# using json.loads() 
import json 
  
# initializing string  
test_string = '{"Nikhil" : 1, "Akshat" : 2, "Akash" : 3}' 
  
# printing original string  
print("The original string : " + str(test_string)) 
  
# using json.loads() 
# convert dictionary string to dictionary 
res = json.loads(test_string) 
  
# print result 
print("The converted dictionary : " + str(res)) 
5
>>> import ast
>>> ast.literal_eval("{'muffin' : 'lolz', 'foo' : 'kitty'}")
{'muffin': 'lolz', 'foo': 'kitty'}
0

New to Communities?

Join the community