[Tutor] Behaviour of dictionaries and others when deleting?
Bill Campbell
bill at celestial.net
Tue May 22 02:02:14 CEST 2007
Is the behaviour defined if one is processing a dictionary using
iteritems, and delete items?
for k, v in d.iteritems():
if somecondition(k, v): del d[k]
Would this process all the original members of the dictionary?
How about doing something similar with bsddb files?
I've always been leary of deleting items while processing things
like this, keeping a list of keys to be deleted, then processing
that list upon completion of the mail loop to delete the items
from the original dictionary or database file.
Bill
--
INTERNET: bill at Celestial.COM Bill Campbell; Celestial Software, LLC
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676
``there is nothing more difficult to take in hand, more perilous to
conduct, or more uncertain in its success, than to take the lead in
the introduction of a new order of things. Because the innovator has
for enemies all those who have done well under the old conditions,
and lukewarm defenders in those who may do well under the new.''
-- Machiavelli
More information about the Tutor
mailing list