I am trying to remove incorrect entries of my dictionary.
I have multiple keys for the same value,

ex,
[111]:[5]
[222]:[5]
[333]:[5}

and I have found out that some key:value pairs are incorrect, and the best
thing to do
is to delete all entries who value is 5. So this is what I am doing:

import numpy
read_dictionary = numpy.load('loc_string_dictionary.npy').item()

for n in read_dictionary:
    print(read_dictionary[n])
    if read_dictionary[n] == '5':
        del read_dictionary[n]


However, I get this error:
RuntimeError: dictionary changed size during iteration

and I can see why.

What's the better thing to do?

thanks!
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to