“Создать словарь из String Python” Ответ

Python создает дикт из строки

# 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))
Bastien Chatelain

Создать словарь из String Python

# Python3 code to convert 
# a string to a dictionary
  
# Initializing String 
string = "{'A':13, 'B':14, 'C':15}"
  
# eval() convert string to dictionary
Dict = eval(string)
print(Dict)
print(Dict['A'])
print(Dict['C'])
dkb234

преобразовать DICT в String Python

my_dict = {"Hello" : True, "World" : False}
print(str(my_dict))
TheProgrammer

Python создает дикт из строки

# 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))
SuperPro Cz

Ответы похожие на “Создать словарь из String Python”

Вопросы похожие на “Создать словарь из String Python”

Больше похожих ответов на “Создать словарь из String Python” по Python

Смотреть популярные ответы по языку

Смотреть другие языки программирования