I have two dictionaries Content_11 and Content_05, inside the dictionary I have checksum for each file which i need to compare , if checksum is matching print something like success else failure for that filename . Following is my data structure and my code snippet is below.
Content_11 = {
"controls": {
"windows-library-1234.zip": "A123455adfasfasdfasdf", # SHA 256 checksum
"unix-library-1234.zip": "a2343dfasdfasdfasdfasdfasdfasdf"
},
"policies": {
"oracle-1234.zip": "A123455adfasfasdfasdfad",
"rhel7-1234.zip": "sdaf23234234234asdf",
}
}
Content_05 = {
"controls": {
"windows-library-1234.zip": "A123455adfasfasdfasdf",
"unix-library-1234.zip": "a2343dfasdfasdfasdfasdfasdfasdf"
},
"policies": {
"oracle-1234.zip": "A123455adfasfasdfasdfad",
"rhel7-1234.zip": "sdaf23234234234asdf",
}
}
I went through some of the questions from stackoverflow and i didnt find the one relevant to me. Any suggestions or improvements are appreciated.
for key_05, value_05 in Content_05.items(): # iterating inside content_05 dict
for key_05_1, value_05_1 in value_05.items(): # iterating inside the content_05 value for getting nested dict
for key_011, value_011 in Content_11.items(): # iterating insde content_11 dict for comparison
for key_11_1, value_11_1 in value_011.items():
if key_05 == key_011:
if value_05_1 == value_11_1:
print "Key {} and its value is {} is matching with {} and hence Success".format(key_05_1,
value_05_1,
value_11_1)
else:
print "Key {} and its value is {} is not matching with {} and hence FAILURE".format(key_05_1,
value_05_1,
value_11_1)