Skip to content

Instantly share code, notes, and snippets.

@kipronokoech
Created July 11, 2020 11:27
Show Gist options
  • Save kipronokoech/72c143ae77e6a5bf844cdc3e40f92b8d to your computer and use it in GitHub Desktop.
Save kipronokoech/72c143ae77e6a5bf844cdc3e40f92b8d to your computer and use it in GitHub Desktop.
# Python3 code to demonstrate
# convert dictionary string to dictionary
# using json.loads()
import ast
# initializing string
string = '{"Kiprono" : 67, "Bob" : 76, "Alice" : 88}'
# printing original string
print(string)
print ("Type before converting:",type(string)) #check type
# using json.loads()
# convert dictionary string to dictionary
res = ast.literal_eval(string)
# print result
print(res)
print("Type after converting: ",type(res)) #check type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment