Answers for "python convert str to dict"

6

convert dict to string python

my_dict = {"Hello" : True, "World" : False}
print(str(my_dict))
Posted by: Guest on December-01-2020
1

convert string representation of dict to dict python

>>> import ast
>>> ast.literal_eval("{'muffin' : 'lolz', 'foo' : 'kitty'}")
{'muffin': 'lolz', 'foo': 'kitty'}
Posted by: Guest on September-20-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

Python Answers by Framework

Browse Popular Code Answers by Language