минимальный пример:
Код: Выделить всё
prev = {'HOST_A': [['OS_TYPE', 'AIX'], ['HAS_COBOL', '0'], ['HAS_TUXEDO', '0'], ['IP', '10.111.160.68'], ['IP', '10.111.160.66'], ['IP', '10.95.0.112']]}
current = {'HOST_A': [['OS_TYPE', 'LINUX'], ['HAS_COBOL', '0'], ['HAS_TUXEDO', '1']]}
# return a dict that contains what is missing in current data
def get_deleted(a, b):
answer = {}
for ki, vi in a.items():
try:
vd = b[ki]
except KeyError:
continue
ls_del = [i for i in vi if i not in vd]
answer[ki] = {}
answer[ki] = ls_del
return answer
b = get_deleted(prev, current)
print('result dict:', b)
for k, v in b.items():
if isinstance(v, list):
isize = len(v)
for value in v:
# print(isize)
if isize >= 1:
print(k, value[0].rstrip(), value[1].rstrip())
Код: Выделить всё
result dict: {'HOST_A': [['OS_TYPE', 'AIX'], ['HAS_TUXEDO', '0'], ['IP', '10.111.160.68'], ['IP', '10.111.160.66'], ['IP', '10.95.0.112']]}
HOST_A OS_TYPE AIX
HOST_A HAS_TUXEDO 0
HOST_A IP 10.111.160.68
HOST_A IP 10.111.160.66
HOST_A IP 10.95.0.112
Код: Выделить всё
result dict: {'HOST_A': [['IP', '10.111.160.68'], ['IP', '10.111.160.66'], ['IP', '10.95.0.112']]}
HOST_A IP 10.111.160.68
HOST_A IP 10.111.160.66
HOST_A IP 10.95.0.112
Подробнее здесь: https://stackoverflow.com/questions/785 ... oved-items