0

I am attempting to extract the differences between two nested dictionaries.

I have installed DeepDiff, which looked like the best option for what I am trying to achieve. I am trying to determine how to change the output so it provides the dictionary values rather than a set which I cannot index. Is there a better way to alter the output (rather than converting the output back to a dictionary)

from __future__ import print_function
from deepdiff import DeepDiff
knownAPs = {'WLC1': {'10.1.1.1': {'72.6': ['AP22', 'city'], '55.1': ['AP102', 'office']}}, 'WLC2': {'10.1.1.2': {}}}
discoveredAPs = {'WLC1': {'10.1.1.1': {}}, 'WLC2': {'10.1.1.2': {}}}
ddiff = DeepDiff(knownAPs, discoveredAPs)
print(ddiff)
if 'dic_item_added' in ddiff.keys():
    print('Item added to known: ' + str((ddiff['dic_item_added'])))
if 'dic_item_removed' in ddiff.keys():
    DisAssociatedAPs = (list(list(ddiff['dic_item_removed'])))
    for i in DisAssociatedAPs:
        keypath = (str(i).strip('root'))
        print("AP's removed from known database: " + str(knownAPs + keypath))
if 'values_changed' in ddiff.keys():
    print('Item changed: ' + str((ddiff['values_changed'])))

Error

{'dic_item_removed': set(["root['WLC1']['10.1.1.1']['72.6']", "root['WLC1']['10.1.1.1']['55.1']"])}
TypeError: unsupported operand type(s) for +: 'dict' and 'str'

Preferred Output

{'dic_item_removed': set(["root['WLC1']['10.1.1.1']['72.6']", "root['WLC1']['10.1.1.1']['55.1']"])}    
AP's removed from known database: ['AP22', 'city']
AP's removed from known database: ['AP102', 'office']
zeepi
  • 33
  • 1
  • 7

0 Answers0