May-25-2024, 08:10 AM
(This post was last modified: May-25-2024, 08:10 AM by Pedroski55.)
The values in the dictionaries are lists, so it is no good just looking at the values, you need to loop through the lists and eliminate values which are also in the comparee dictionary.
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': []} # dict1 and dict2 have the same keys dict1.keys() == dict2.keys() # True dict3 = {} dict4 = {} # if the value is an empty list, it will not be removed for key in dict1.keys(): print(f'key = {key}, value = {dict1[key]}') print(f'key = {key}, value = {dict2[key]}') dict3[key] = [dict1[key][i] for i in range(len(dict1[key])) if dict1[key][i] not in dict2[key]] dict4[key] = [dict2[key][i] for i in range(len(dict2[key])) if dict2[key][i] not in dict1[key]] # have a look # compare the corresponding dictionaries for key in dict1.keys(): print('dict1 and dict3') print(f'This is dict1: key = {key}, value = {dict1[key]}') print(f'This is dict3: key = {key}, value = {dict3[key]}') print('\ndict2 and dict4 \n') print(f'This is dict2: key = {key}, value = {dict2[key]}') print(f'This is dict4: key = {key}, value = {dict4[key]}')Fun on Saturday morning!