Delete common entries between two dictionaries

Derrick 'dman' Hudson dman at dman13.dyndns.org
Mon Nov 24 16:52:48 EST 2003


On Mon, 24 Nov 2003 13:24:17 -0800, Amy G wrote:
> I have received such good help on this message board.  I wonder if I
> might not get a little more help from you on this.
> 
> I am at the point where I have two dictionaries, with information of
> a domain and a frequency of that domain.
> 
> Now that I have the two, I want to delete each entry from one that
> the two have in common, leaving only those that are unique to the
> dictionary?

This would be great for sets, if a set adequately models your data.
(with two sets, this would simply be  (s1-(s1&s2)))

> Say I have a dictionary called domains_black and another
> domains_white...

Did you want to define equality by key or by (key, value) pair?

for key in domains_white.keys() :
    if key in domains_black: del domains_black[key]

for key in domains_white.keys() :
    if key in domains_black and domains_white[key] == domains_black[key] :
        del domains_black[key]

-D

-- 
He who scorns instruction will pay for it,
but he who respects a command is rewarded.
        Proverbs 13:13
 
www: http://dman13.dyndns.org/~dman/            jabber: dman at dman13.dyndns.org




More information about the Python-list mailing list