Is it legitimate to delete items from a dictionary in Python while iterating over it?
For example:
for k, v in mydict.iteritems():
if k == val:
del mydict[k]
The idea is to remove elements that don’t meet a certain condition from the dictionary, instead of creating a new dictionary that’s a subset of the one being iterated over.
Is this a good solution? Are there more elegant/efficient ways?