Change the original dict:
for k,v in your_dic.items(): if v == 'DNC': del your_dic[k]
or create a new dict using dict comprehension:
your_dic = {k:v for k,v in your_dic.items() if v != 'DNC'}
From docs to iteritems() , iterkeys() and itervalues() :
Using iteritems() , iterkeys() or itervalues() when adding or deleting entries in a dictionary can lead to a RuntimeError or crash to iterate over all entries.
The same goes for the normal for key in dic: loop.
In Python 3, this applies to dict.keys() , dict.values() and dict.items() .
source share