“Crear diccionario de String Python” Código de respuesta

Python creando un dict de una cadena

# 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

Crear diccionario de 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

convertir dict a string python

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

Python creando un dict de una cadena

# 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

Respuestas similares a “Crear diccionario de String Python”

Preguntas similares a “Crear diccionario de String Python”

Más respuestas relacionadas con “Crear diccionario de String Python” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código