I have 7 dictionaries that I would like to merge one with the other:
The dictionaries have been tested individually and all seem to follow the same structure:
results1()=
{
"NO4":
{
"type_tests":
{
"test1":1.0,
"test2":5.0,
"test3":14.0
}
},
"SO3":
{
"type_tests":
{"test1":1.0,
"test2":5.0,
"test3":14.0}
}
}
results2()=
{
"CO2":
{
"type_tests":
{
"test1":10.0,
"test2":51.0,
"test3":34.0
}
},
"H20":
{
"type_tests":
{"test1":1.0,
"test2":5.0,
"test3":14.0}
}
}
I have tried to merge the 7 dictionaries following this post:
How to merge two dictionaries in a single expression?
in the way that what I have tried is merge the functions that output the dictionaries this way:
merge_dictionaries={**results1(),**results2(),**results3(),**results4(),**results5(),**results6(),**results7()}
return merge_dictionaries
however when I run merge dictionaries, it outputs:
TypeError: 'str' object is not a mapping
I have also seen this post merging "several" python dictionaries , and i tried :
dicts=[results1(),results2(),results3(),results4(),results5(),results6(),results7()]
for d in dicts:
for k, v in d.iteritems():
super_dict[k].add(v)
return superdict
however outputs results7()
dictionary and stays thinking (as if it was supposed to output something else but does not)
The desired output using the 2 dictionaries would be the dictionaries merged:
{
"NO4":
{
"type_tests":
{
"test1":1.0,
"test2":5.0,
"test3":14.0
}
},
"SO3":
{
"type_tests":
{
"test1":1.0,
"test2":5.0,
"test3":14.0
}
},
"CO2":
{
"type_tests":
{
"test1":10.0,
"test2":51.0,
"test3":34.0
}
},
"H20":
{
"type_tests":
{
"test1":1.0,
"test2":5.0,
"test3":14.0
}
}
}
how could I get a super dictionary merging the 7 individual dictionaries?