I have two nested dictionaries.
dict1 = {(t1,name):{('11','22'):{'33':'456','77':'891'},
('121','212'):{'32':'123', '23':'546'}}}
dict2 = {(t1,name):{('11','22'):{'33':'456','77':'891'},
('121','212'):{'32':'123', '23':'546'}}}
Basically both the dicts are same. But I need to compare each key in dict1
and see if that key exists in dict2
(if exists the corresponding value should be matched with dict1
value).
Here is what I have written. But couldn't get the end result.
for i,j in dict1.items():
# values of t1,name (i.e. inner key/value pairs of (t1,name)) might interchange
# order at times that is the reason I used sorted
for k,v in sorted(j.items()):
print k # prints - >('11',22')
print v # prints - > '33':'456','77':'891'
if i in dict2.keys():
# Here I need to make sure for outer key (t1,name), inner key/value pair of
# dict2 is same as inner key/value pair of dict1
Apologies for this lengthy explanation. I'm not sure whether I am able to explain it clearly.