Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

text to dictionary python

Method 1:
# Python3 code to demonstrate
# convert dictionary string to dictionary
# using ast.literal_eval()
import ast

# initializing string
test_string = '{"Nikhil" : 1, "Akshat" : 2, "Akash" : 3}'

# printing original string
print("The original string : " + str(test_string))

# using ast.literal_eval()
# convert dictionary string to dictionary
res = ast.literal_eval(test_string)

# print result
print("The converted dictionary : " + str(res))


Method 2:
# Python3 code to demonstrate
# convert dictionary string to dictionary
# using json.loads()
import json

# initializing string
test_string = '{"Nikhil" : 1, "Akshat" : 2, "Akash" : 3}'

# printing original string
print("The original string : " + str(test_string))

# using json.loads()
# convert dictionary string to dictionary
res = json.loads(test_string)

# print result
print("The converted dictionary : " + str(res))
Comment

convert response text to dictionary python

import requests
 
# Making a get request
response = requests.get('https://api.github.com')
 
# printing request text
print(response.text)
Comment

PREVIOUS NEXT
Code Example
Python :: python get current time in hours minutes and seconds 
Python :: how to import mnist dataset keras 
Python :: text to binary python 
Python :: kaaba python tutorial 
Python :: how to obtain the content of brackets 
Python :: How to add card in trello API using python 
Python :: position in list python 
Python :: when pyspark 
Python :: add empty column to dataframe pandas 
Python :: pandas extract month year from date 
Python :: permutations python 
Python :: python write list to text file 
Python :: cv2.adaptiveThreshold() python 
Python :: plot pandas figsize 
Python :: django run queryset in terminal 
Python :: panda - subset based on column value 
Python :: how to take two integers as input in python 
Python :: display current local time in readable format 
Python :: how to add headings to data in pandas 
Python :: cv2 add circle to image 
Python :: seconds in a month 
Python :: connect to mysql database jupyter 
Python :: python how to get every name in folder 
Python :: python 3 play sound 
Python :: add download directory selenium python 
Python :: python how to remove the title of the index from dataframe 
Python :: python csv add row 
Python :: qtextedit get text 
Python :: convert hex to decimal python 
Python :: python read arguments 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =