May-24-2024, 04:10 PM
(This post was last modified: May-24-2024, 04:11 PM by deanhystad.)
I'm not sure if this is right since you never clarified what "duplicate" means in this particular case, but here's your band-aid.
dict1 = {"SAG01112_SSAP_HA_LPM": [["OS_TYPE", "AIX"], ["IS_COBOL", "1"]], "SAP": [], "C11_RG": [], "W11_RG": []} dict2 = { "SAG01112_SSAP_HA_LPM": [ ["OS_TYPE", "AIX"], ["IP", "172.17.10.112"], ["IP", "10.111.160.119"], ["IP", "10.111.160.68"], ["IP", "10.111.160.66"], ["IP", "10.95.0.112"], ["IP", "10.111.162.119"], ], "SAP": [], "C11_RG": [], "W11_RG": [], } def remove_common_items(dict_a, dict_b): """Remove values that are common to a and b.""" # For common keys for key in set(dict_a) & set(dict_b): a = dict_a[key] b = dict_b[key] # Remove items common to both value lists. for item in [x for x in a if x in b]: # Make list of common before iterating a.remove(item) b.remove(item) remove_common_items(dict1, dict2) print(dict1) print(dict2)I still think you dictionaries are messed up and should look like this: