Scenario:
1.How to convert the below key value string pair without quotes to dictionary.
employee='{"Priority":{0:"High"},"Age":{range(0,5):"high"}}'
CodePudding user response:
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'>