“python usando a lista como chave de dicionário” Respostas de código

Listas para o Dicionário Python

#This is to convert two lists into a dictionary in Python

#given ListA is key
#given ListB is value

listA = ['itemA','itemB']
listB = ['priceA','priceB']
dict(zip(listA, listB))

# Returns 
{'itemA': 'priceA',
 'itemB': 'priceB'
}
Frightened Ferret

Converter teclas de dicionário para listar Python

newlist = list()
for i in newdict.keys():
    newlist.append(i)
Thoughtless Tiger

python usando a lista como chave de dicionário

# Declaring a dictionary
d = {} 
  
# This is the list which we are 
# trying to use as a key to
# the dictionary
a =[1, 2, 3, 4, 5]
  
# converting the list a to a string
p = str(a)
d[p]= 1
  
# converting the list a to a tuple
q = tuple(a) 
d[q]= 1
  
for key, value in d.items():
    print(key, ':', value)
Jepsiko

Respostas semelhantes a “python usando a lista como chave de dicionário”

Perguntas semelhantes a “python usando a lista como chave de dicionário”

Mais respostas relacionadas para “python usando a lista como chave de dicionário” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código