i am trying to compare keys of different dictionaries stored in json.if keys are same then store those keys in another dictionary but i am not getting the required output. input looks like:
[
{
"huma":10,
"sana":25
},
{
"sara":12,
"huma":20,
" zeb:15
}
]
what i tried is:
def compare():
result_dictionary = {}
with open('data.json') as data_file:
data = json.load(data_file)
for d1 in data:
for key, value in d1.items():
print("key: {key} | value: {value}".format(key=key, value=value))
compare()
i am confused how to compare these keys of multiple dictionaries and key which matches store them in a new dictionary? the output should be "Huma"because only that is equal in both dictionaries.