Answers for "convert a string to dictionary python"

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
-1

python convert b string to dict

# python3
import ast
byte_str = b"{'one': 1, 'two': 2}"
dict_str = byte_str.decode("UTF-8")
mydata = ast.literal_eval(dict_str)
print(repr(mydata))
Posted by: Guest on November-25-2020

Code answers related to "convert a string to dictionary python"

Python Answers by Framework

Browse Popular Code Answers by Language