Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

[Python]: How to convert Convert key value string without quotes in string to dictionary

Scenario:

1.How to convert the below key value string pair without quotes to dictionary.

employee='{"Priority":{0:"High"},"Age":{range(0,5):"high"}}'

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Using eval to execute the expression will return the dictionary

employee = '{"Priority":{0:"High"},"Age":{range(0,5):"high"}}'

dict_ = eval(employee)
print(dict_)  # {'Priority': {0: 'High'}, 'Age': {range(0, 5): 'high'}}
print(type(dict_))  # <class 'dict'>

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading