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以获得相似键的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)
                    <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>