removing dictionary key-pair

J

JD

Hello,

I try to remove a dictionary key-pair (remove an entry),
but I'm unsuccessful. Does anyone know how to achieve this?

Thanks
 
B

bruno at modulix

JD said:
Hello,

I try to remove a dictionary key-pair (remove an entry),
but I'm unsuccessful. Does anyone know how to achieve this?

Thanks

mydict = {"key" : "value"}
del mydict(key)
 
A

akameswaran

JD said:
Hello,

I try to remove a dictionary key-pair (remove an entry),
but I'm unsuccessful. Does anyone know how to achieve this?

Thanks

Assuming you know the key:

d = {"foo":1,"bar":2}
print d
del(d["foo"])
print d
 
D

danmcleran

JD said:
Hello,

I try to remove a dictionary key-pair (remove an entry),
but I'm unsuccessful. Does anyone know how to achieve this?

Thanks

d = dict(a=1, b=2, c=3)

print d

del d['a']

print d
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top