JD wrote:[color=blue]
> Hello,
>
> I try to remove a dictionary key-pair (remove an entry),
> but I'm unsuccessful. Does anyone know how to achieve this?
>
> Thanks[/color]
mydict = {"key" : "value"}
del mydict(key)
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb@xiludom. gro'.split('@')])"
JD wrote:[color=blue]
> Hello,
>
> I try to remove a dictionary key-pair (remove an entry),
> but I'm unsuccessful. Does anyone know how to achieve this?
>
> Thanks[/color]
Assuming you know the key:
d = {"foo":1,"bar": 2}
print d
del(d["foo"])
print d
bruno at modulix wrote:[color=blue]
> JD wrote:
>[color=green]
>>Hello,
>>
>>I try to remove a dictionary key-pair (remove an entry),
>>but I'm unsuccessful. Does anyone know how to achieve this?
>>
>>Thanks[/color]
>
>
> mydict = {"key" : "value"}
> del mydict(key)[/color]
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 'onurb@xiludom. gro'.split('@')])"
JD wrote:[color=blue]
> Hello,
>
> I try to remove a dictionary key-pair (remove an entry),
> but I'm unsuccessful. Does anyone know how to achieve this?
>
> Thanks[/color]
JD wrote:[color=blue]
> Hello,
>
> I try to remove a dictionary key-pair (remove an entry),
> but I'm unsuccessful. Does anyone know how to achieve this?
>
> Thanks[/color]
[color=blue][color=green][color=darkred]
>>> d = {1: "one", 2: "two", 3: "three"}
>>> del d[2]
>>> d[/color][/color][/color]
{1: 'one', 3: 'three'}[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
Comment