Assume I have the following two dictionaries:
dict1 =
{
'battery1' : { 'Charge': 'enable', 'Discharge': 'enable' },
'battery2' : { 'Charge': 'enable', 'Discharge': 'enable' }
}
dict2 =
{
'Estimated battery run-time': '05:00 minutes',
'battery1': {'Device': 'controller', 'Discharge': 'enable',
'Charging State': 'Fully charged', 'Charge': 'disable'},
'battery2': {'Device': 'controller', 'Discharge': 'enable',
'Charging State': 'Fully charged', 'Charge': 'disable'}
}
I would like to check if dict1 is a subset of dict2 (i.e if the key value pairs in dict 1 are shown in dict2, while its OK that the same keys in dict2 will include EXTRA values like Charging state and Device).
for k, v in dict1.iteritems():
for t, c in v.iteritems():
if k in dict2:
if c != dict2[k][v]:
mismatch = true
break;
But I get
unhashable type: 'dict' error.
Note that this is a different question than:
Loop through all nested dictionary values?
Taking sums of nested values of nested dictionary
Iterate over nested dictionary
Can someone please assist?
Thanks in advance.