我需要添加/加入三个带有公共密钥和不同值的字典我需要将所有三个字典作为单个字典连接在一起,它们应该连接在一起。我有:
Dict1 = {"a" : 10 ,"b" : "vignesh", "C" : "bangalore"}
Dict2 = {"a" : 25 ,"b" : "logesh", "C" : "mumbai"}
Dict3 = {"a" : 25 ,"b" : "logesh", "C" : "mumbai"}
我需要输出为:
Dict4 = { "i1" : {"a" : 10 ,"b" : "vignesh", "C" : "bangalore"},"i2" : {"a" : 25 ,"b" : "logesh", "C" : "mumbai"} , "i3" : {"a" : 25 ,"b" : "logesh", "C" : "mumbai"} }
答案 0 :(得分:0)
试试这段代码。我还附上了输出的截图。
Dict1 = {"a" : 10 ,"b" : "vignesh", "C" : "bangalore"}
Dict2 = {"a" : 25 ,"b" : "logesh", "C" : "mumbai"}
Dict3 = {"a" : 25 ,"b" : "logesh", "C" : "mumbai"}
Dict4 = { }
Dict4["i1"]=Dict1;
Dict4["i2"]=Dict2;
Dict4["i3"]=Dict3;
print(Dict4)
答案 1 :(得分:-1)
这样可以满足您的需求:
dict(i1=Dict1,i2=Dict2,i3=Dict3)