Deleting dictionary items
Patricia Hawkins
phawkins at connact.com
Thu Apr 5 23:15:15 EDT 2001
>>>>> "WN" == Will Newton <will at nospam.misconception.org.uk> writes:
WN> What's the best way to delete dictionary items?
WN> I have a dictionary with tuples as keys, and I would like to delete all
WN> keys with a certain element. First I wrote:
WN> for item in td.data.keys():
WN> if item[attr] != value:
WN> del td.data[item]
WN> But will this work?
Your code contradicts your text (do you mean "with a certain element",
or != value?) so it's hard to tell what you want. But this code
snippet is really easy to play with -- why don't you fire up a python
interpreter and see what it does?
--
Patricia J. Hawkins
Hawkins Internet Applications, LLC
More information about the Python-list
mailing list