Deleting dictionary items
Carl Banks
idot at vt.edu
Sat Mar 17 14:43:33 EST 2001
Will Newton <will at nospam.misconception.org.uk>,
exactly what drugs were you under the influence of when you wrote:
>
> 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?
Probably not. This might work, though:
for item in td.data.keys():
if item[attr] == value:
del td.data[item]
--
CARL BANKS
"I like nothing better than a good challenge.
This is not one of them."
More information about the Python-list
mailing list