Jump to content

Archived

This topic is now archived and is closed to further replies.

jknet

Deletar elemento pela chave do dicionario

Recommended Posts

Boa noite gente, to querendo deletar o elemento usando a chave mas nao deu certo,

 

progs = {"yes":["Close to the Edge","Fragile"],"Genesis":["Foxtrot","the Nursery Crime"],"Elp":["Brian Salad Surgery"]}

 

print(len(progs))

4

 

if(progs.has_key("Elp")):

del (progs["Elp"])

 

print(len(progs))

4

 

era pa sair 3, mas nao deletou, qual comando uso p resolver ?

Share this post


Link to post
Share on other sites

Aqui funciona na versão 2.7.

 

 

>>> progs = {"yes":["Close to the Edge","Fragile"],"Genesis":["Foxtrot","the Nursery Crime"],"Elp":["Brian Salad Surgery"]}
>>> print(len(progs))
3

>>> if progs.has_key('Elp'):
...   del(progs['Elp'])
...
>>> print(len(progs))
2

Share this post


Link to post
Share on other sites

×

Important Information

Ao usar o fórum, você concorda com nossos Terms of Use.