Hi,

I need to keep an updated dictionary of pictures in my application.  I have a function which takes snapshots of the current pictures available.  Some of the pictures in my dictionary have been deleted, so their dict entry needs to be removed.  Here is a snippet of very ugly code I have which works.  I'm looking for quick suggestions for a better implementation-- all nice replies welcomed!

Thanks,
Marcus

-- code snippet

# 1st, find the 'stale' items in our dictionary to delete
# lstKeepers is a list of current pictures
# Note: if I try to iterate over the keys of the dict and
# remove-as-I-go, I get an exception (dict size changed
# during iteration)
lstRemove = []
for key in myDict:
   if key not in lstKeepers:
       lstRemove.append(key)
 
# 2nd, remove them
for oldKey in lstRemove:
   del myDict[oldKey]
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to