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}
}
}
我试着把这篇文章后面的7本词典合并起来:
How to merge two dictionaries in a single expression?
merge_dictionaries={**results1(),**results2(),**results3(),**results4(),**results5(),**results6(),**results7()}
return merge_dictionaries
但是,当我运行合并字典时,它会输出:
TypeError: 'str' object is not a mapping
merging "several" python dictionaries
,我试着:
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
results7()
字典并保持思考(好像它应该输出其他东西,但没有)
使用这两个字典的所需输出将是合并的字典:
{
"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
}
}
}
我怎样才能把这7本字典合并成一本超级字典呢?