1. <legend id='toyYq'><style id='toyYq'><dir id='toyYq'><q id='toyYq'></q></dir></style></legend>
      <i id='toyYq'><tr id='toyYq'><dt id='toyYq'><q id='toyYq'><span id='toyYq'><b id='toyYq'><form id='toyYq'><ins id='toyYq'></ins><ul id='toyYq'></ul><sub id='toyYq'></sub></form><legend id='toyYq'></legend><bdo id='toyYq'><pre id='toyYq'><center id='toyYq'></center></pre></bdo></b><th id='toyYq'></th></span></q></dt></tr></i><div id='toyYq'><tfoot id='toyYq'></tfoot><dl id='toyYq'><fieldset id='toyYq'></fieldset></dl></div>

        <small id='toyYq'></small><noframes id='toyYq'>

      1. <tfoot id='toyYq'></tfoot>

          <bdo id='toyYq'></bdo><ul id='toyYq'></ul>

        比较python中的两个dict以获得相似键的最大值

        comparing two dict in python to get the maximum value for similar key(比较python中的两个dict以获得相似键的最大值)

          • <tfoot id='J1Rpp'></tfoot>

            <small id='J1Rpp'></small><noframes id='J1Rpp'>

          • <i id='J1Rpp'><tr id='J1Rpp'><dt id='J1Rpp'><q id='J1Rpp'><span id='J1Rpp'><b id='J1Rpp'><form id='J1Rpp'><ins id='J1Rpp'></ins><ul id='J1Rpp'></ul><sub id='J1Rpp'></sub></form><legend id='J1Rpp'></legend><bdo id='J1Rpp'><pre id='J1Rpp'><center id='J1Rpp'></center></pre></bdo></b><th id='J1Rpp'></th></span></q></dt></tr></i><div id='J1Rpp'><tfoot id='J1Rpp'></tfoot><dl id='J1Rpp'><fieldset id='J1Rpp'></fieldset></dl></div>
              <bdo id='J1Rpp'></bdo><ul id='J1Rpp'></ul>
                <tbody id='J1Rpp'></tbody>
              1. <legend id='J1Rpp'><style id='J1Rpp'><dir id='J1Rpp'><q id='J1Rpp'></q></dir></style></legend>

                  本文介绍了比较python中的两个dict以获得相似键的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有这两个字典:

                  a={"test1":90,  "test2":45,  "test3":67,  "test4":74}
                  b={"test1":32,  "test2":45,  "test3":82,  "test4":100}
                  

                  如何提取同一键的最大值以获得新的字典,如下所示:

                  how to extract the maximum value for the same key to get new dict as this below:

                  c={"test1":90,  "test2":45,  "test3":82,  "test4":100}
                  

                  推荐答案

                  你可以这样试试,

                  >>> a={"test1":90, "test2":45, "test3":67, "test4":74} 
                  >>> b={"test1":32, "test2":45, "test3":82, "test4":100}
                  >>> c = { key:max(value,b[key]) for key, value in a.iteritems() }
                  >>> c
                  {'test1': 90, 'test3': 82, 'test2': 45, 'test4': 100}
                  

                  这篇关于比较python中的两个dict以获得相似键的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
                    <tbody id='O7uZ3'></tbody>

                  <tfoot id='O7uZ3'></tfoot>
                1. <i id='O7uZ3'><tr id='O7uZ3'><dt id='O7uZ3'><q id='O7uZ3'><span id='O7uZ3'><b id='O7uZ3'><form id='O7uZ3'><ins id='O7uZ3'></ins><ul id='O7uZ3'></ul><sub id='O7uZ3'></sub></form><legend id='O7uZ3'></legend><bdo id='O7uZ3'><pre id='O7uZ3'><center id='O7uZ3'></center></pre></bdo></b><th id='O7uZ3'></th></span></q></dt></tr></i><div id='O7uZ3'><tfoot id='O7uZ3'></tfoot><dl id='O7uZ3'><fieldset id='O7uZ3'></fieldset></dl></div>
                  <legend id='O7uZ3'><style id='O7uZ3'><dir id='O7uZ3'><q id='O7uZ3'></q></dir></style></legend>

                      <small id='O7uZ3'></small><noframes id='O7uZ3'>

                        <bdo id='O7uZ3'></bdo><ul id='O7uZ3'></ul>