removing redundant elements in a dictionary

Astan Chee stanc at
Wed Aug 1 05:50:03 CEST 2007

I have a dictionary which looks something like this:

elem = 

what Im trying to do is find all keys in the list that have the same 
value and delete those (except one); thereby removing all redundant keys 
so that the above dict will look like this:

elem = {"co":[1,2,3],"pp":[5,6,7],"qa":[8,7,6]}

my code so far looks like this:

for out1 in elem.keys():
    for out2 in elem.keys():
        if out1 != out2:
            if elem[out1] == elem[out2]:
                del elem[out1]

This returns in a KeyError exception when sorting. What am I missing here?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list