Nested dictionary cleanup

Emile van Sebille emile at
Mon Nov 3 22:35:11 CET 2003

Colin Brown:
> My code fragment below:
> for key1 in dict1.keys():

here you realize an iterable list

>     for key2 in dict1[key1]:

here you step through an iterator.  If you change this to
        for key2 in dict1[key1].keys():

and assuming I've guessed appropriately, you might get what you're looking

>         if dict1[key1][key2] == None:
>             del dict1[key1][key2]

Emile van Sebille
emile at

More information about the Python-list mailing list