python如何把多个字典合并为1个?

需求:

  •   我需要把3个字典合并为1个。

解决:

  • 利用{}.update
  • 代码是:
  • l = [{"json":"True",},
        {"cpu":78.5,"mem":11},
        {"apu":88},
         ]
    res_all ={}
    res_all.update(l[0])
    res_all.update(l[1])
    res_all.update(l[2])
    print(res_all)

     

 

参考资料:

https://blog.csdn.net/weixin_44346972/article/details/106747178

https://blog.csdn.net/Jerry_1126/article/details/73017270

posted @ 2022-11-25 15:13  o蹲蹲o  阅读(132)  评论(0编辑  收藏  举报