Hi
Trying to create a function that takes two dictionaries, and deletes key:values that are common in both dictionaries. So far I have the following; but I can only delete values in one dictionary as I am iterating over the other. Or is there a way to rename keys in dictionaries? Thanks in advance.
Cheers
Trying to create a function that takes two dictionaries, and deletes key:values that are common in both dictionaries. So far I have the following; but I can only delete values in one dictionary as I am iterating over the other. Or is there a way to rename keys in dictionaries? Thanks in advance.
Code:
def filterByKey(dict1, dict2): ''' Takes two dictionaries and deletes matching records; Dict1 is the main dictionary; Dict2 is the secondary dictionary. RETURNS: dictionary Dict1 of unique values. ''' for key in dict2: if key in dict1.keys(): del dict1[key] return dict1
Comment