I have 2 nested dictionaries (python load data from excel). I need look in dictionary1 [dict1] if exists text "AVIS" and in the same time - look in dictionary2 [dict2] whether inside we have the same amount as in dict1 and text: "TP". E.g:
dict1 = {1: {1: '1', 2: 'D1', 3: '45748268', 4: '2017-08-31 00:00:00', 5: 'None', 6: '3249503', 7: 'AVIS109966', 8: 'None', 9: '77434.85'}, 2: {1: '1', 2: 'D1', 3: '45748505', 4: '2017-08-31 00:00:00', 5: 'None', 6: '3249503', 7: 'AVIS109966', 8: 'None', 9: '14273.7'}, 3: {1: '1', 2: 'D1', 3: '45748576', 4: '2017-08-31 00:00:00', 5: 'None', 6: '3249503', 7: 'AVIS109966', 8: 'None', 9: '254005.75'}}
dict2 = {1: {1: '1302970', 2: '1900002349', 3: 'KR', 4: None, 5: '@AG\\QOverdue@', 6: 'FQ', 7: 'U', 8: 'ZB14', 9: None, 10: 'Kst 0970 03/17', 11: 'AV01FOJ', 12: datetime.datetime(2017, 4, 21, 0, 0), 13: datetime.datetime(2017, 9, 1, 0, 0), 14: datetime.datetime(2017, 5, 25, 0, 0), 15: -179270.4, 16: 'EUR', 17: -179270.4, 18: 'EUR'}, 2: {1: 'TP 109966', 2: '1900002116', 3: 'KR', 4: None, 5: '@AG\\QOverdue@', 6: 'FQ', 7: 'U', 8: 'ZB14', 9: None, 10: 'KST 0970 04/2017', 11: 'AV016OI', 12: datetime.datetime(2017, 5, 17, 0, 0), 13: datetime.datetime(2017, 7, 11, 0, 0), 14: datetime.datetime(2017, 6, 25, 0, 0), 15: -359228.17, 16: 'EUR', 17: 254005.75, 18: 'EUR'}}
Look at above example: correct key in dict1 is key no 3 (because we have "AVIS" text [key no 7], "TP" text in dict2 [key no 1], and amount from this key in dict1 and dict2 is the same [key9 and 17].
My sample code below (but it doesnt works):
print("\n\n")
bezTP1 = {}
bezTP2 = {}
matok = {}
matok2 = {}
licznik3 = 1
for key in dict:
matpro = dict[key]
for j in matpro:
if j == 1:
bezTP1[key] = {}
bezTP1[key][j] = matpro[j]
########### Check in dict1 if AVIS text exists ###################
if "AVIS" in str(matpro[j]):
for key2 in dict2:
matpro2 = dict2[key2]
for t in matpro2:
if t == 1:
bezTP2[key2] = {}
bezTP2[key2][t] = matpro2[t]
########### check in dict2 if TP text exist and amount from
this key is the same as in dict2 ##################
if ("TP" in str(matpro2[t]) and (matpro2[17] == matpro[9])):
for x in matpro:
if x == 1:
matok[licznik3] = {}
matok[licznik3][x] = matpro[x]
licznik3 += 1
Aucun commentaire:
Enregistrer un commentaire