Answers for "if you have a string that looks like a dict in python how do you turn it into a dict"

3

poython str to dict

>>> D1={'1':1, '2':2, '3':3}
>>> s=str(D1)
>>> import ast
>>> D2=ast.literal_eval(s)
>>> D2
{'1': 1, '2': 2, '3': 3}
Posted by: Guest on June-30-2020

Code answers related to "if you have a string that looks like a dict in python how do you turn it into a dict"

Python Answers by Framework

Browse Popular Code Answers by Language