Deleting dictionary items
Emile van Sebille
emile at fenx.com
Sat Mar 17 09:32:54 EST 2001
I'm not clear on what you're asking, but I think you want to delete keys
from a dictionary where a certain value is one of the elements of the tuple
that is the key. Does this do it:
# delete keys from mvDict where value in key
for key in myDict.keys():
if value in key:
del myDict(key)
Emile van Sebille
emile at fenx.com
"Will Newton" <will at nospam.misconception.org.uk> wrote in message
news:98ug6n$q9d$1 at news6.svr.pol.co.uk...
>
> What's the best way to delete dictionary items?
>
> I have a dictionary with tuples as keys, and I would like to delete all
> keys with a certain element. First I wrote:
>
> for item in td.data.keys():
> if item[attr] != value:
> del td.data[item]
>
>
> But will this work?
More information about the Python-list
mailing list