May-27-2024, 10:25 AM
(May-25-2024, 08:10 AM)Pedroski55 Wrote: 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!
this does not work either...
root@ssap: /tmp # ./aix_reg_client_tcp_dev.py --run-now changed: {'SAG01112_SSAP_HA_LPM': [['UPTIME', '109\n']]} ONLY ECHO, NOTHING SENT TO SERVER DEBUG ON: STD|1|SAG01112_SSAP_HA_LPM|UPTIME|109|599acfaa8d5d1c04a19324461bed1003 deleted: {'SAG01112_SSAP_HA_LPM': [['UPTIME', '108\n']], 'SAP': [], 'C11_RG': [], 'W11_RG': []} key = SAG01112_SSAP_HA_LPM, value = [['UPTIME', '108\n']] key = SAG01112_SSAP_HA_LPM, value = [['UPTIME', '109\n']] key = SAP, value = [] Traceback (most recent call last): File "/tmp/./aix_reg_client_tcp_dev.py", line 757, in <module> reg_client_runner() File "/tmp/./aix_reg_client_tcp_dev.py", line 718, in reg_client_runner del_data_filtered = remove_common_items(del_data, changed_data) File "/tmp/./aix_reg_client_tcp_dev.py", line 138, in remove_common_items print(f'key = {key}, value = {dict2[key]}') KeyError: 'SAP'