Qn: Nested dictionary cleanup

Colin Brown cbrown at metservice.com
Mon Nov 3 16:09:26 EST 2003


My code fragment below:

for key1 in dict1.keys():
    for key2 in dict1[key1]:
        if dict1[key1][key2] == None:
            del dict1[key1][key2]

gives the following error:
RuntimeError: dictionary changed size during iteration

Any suggestion on how to code this please.

Thanks
Colin Brown
PyNZ







More information about the Python-list mailing list