Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > removing dictionary key-pair

Reply
Thread Tools

removing dictionary key-pair

 
 
JD
Guest
Posts: n/a
 
      06-09-2006

Hello,

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

Thanks
 
Reply With Quote
 
 
 
 
bearophileHUGS@lycos.com
Guest
Posts: n/a
 
      06-09-2006
JD>I try to remove a dictionary key-pair (remove an entry),

>>> d = {1:2, 3:4}
>>> d

{1: 2, 3: 4}
>>> del d[1]
>>> d

{3: 4}

Bye,
bearophile

 
Reply With Quote
 
 
 
 
bruno at modulix
Guest
Posts: n/a
 
      06-09-2006
JD wrote:
> 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)

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in ''.split('@')])"
 
Reply With Quote
 
akameswaran@gmail.com
Guest
Posts: n/a
 
      06-09-2006

JD wrote:
> 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

 
Reply With Quote
 
bruno at modulix
Guest
Posts: n/a
 
      06-09-2006
bruno at modulix wrote:
> JD wrote:
>
>>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)


grmf... Typo. This is:

del mydict['key']

of course...
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in ''.split('@')])"
 
Reply With Quote
 
danmcleran@yahoo.com
Guest
Posts: n/a
 
      06-09-2006

JD wrote:
> 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

 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      06-09-2006
JD wrote:
> 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 = {1: "one", 2: "two", 3: "three"}
>>> del d[2]
>>> d

{1: 'one', 3: 'three'}
>>>


regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Love me, love my blog http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance ordered dictionary vs normal dictionary Navkirat Singh Python 6 07-29-2010 10:18 AM
Re: Performance ordered dictionary vs normal dictionary Chris Rebert Python 0 07-29-2010 06:11 AM
creating a dictionary from a dictionary with regex james_027 Python 1 08-22-2007 07:39 AM
[DICTIONARY] - Copy dictionary entries to attributes Ilias Lazaridis Python 6 02-21-2006 11:27 AM
dictionary within dictionary Fox ASP General 5 03-13-2005 05:03 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57