Q:

poython str to dict

# Python3 code to demonstrate 
# convert dictionary string to dictionary 
# using ast.literal_eval() 
import ast 
  
# initializing string  
test_string = '{"Nikhil" : 1, "Akshat" : 2, "Akash" : 3}' 

# using ast.literal_eval() 
# convert dictionary string to dictionary 
res = ast.literal_eval(test_string) 
  
0
>>> D1={'1':1, '2':2, '3':3}
>>> s=str(D1)
>>> import ast
>>> D2=ast.literal_eval(s)
>>> D2
{'1': 1, '2': 2, '3': 3}

3

New to Communities?

Join the community