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

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

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

        独特词典列表

        List of unique dictionaries(独特词典列表)

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

          <tbody id='ptmHI'></tbody>

        <tfoot id='ptmHI'></tfoot>
          <bdo id='ptmHI'></bdo><ul id='ptmHI'></ul>
          • <legend id='ptmHI'><style id='ptmHI'><dir id='ptmHI'><q id='ptmHI'></q></dir></style></legend>

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

                1. 本文介绍了独特词典列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我有一个字典列表:

                  [
                      {'id': 1, 'name': 'john', 'age': 34},
                      {'id': 1, 'name': 'john', 'age': 34},
                      {'id': 2, 'name': 'hanna', 'age': 30},
                  ]
                  

                  如何获取唯一词典列表(删除重复项)?

                  [
                      {'id': 1, 'name': 'john', 'age': 34},
                      {'id': 2, 'name': 'hanna', 'age': 30},
                  ]
                  

                  推荐答案

                  因此使用密钥id创建一个临时字典。这会过滤掉重复项。 词典的values()将是列表

                  在Python2.7中

                  >>> L=[
                  ... {'id':1,'name':'john', 'age':34},
                  ... {'id':1,'name':'john', 'age':34},
                  ... {'id':2,'name':'hanna', 'age':30},
                  ... ]
                  >>> {v['id']:v for v in L}.values()
                  [{'age': 34, 'id': 1, 'name': 'john'}, {'age': 30, 'id': 2, 'name': 'hanna'}]
                  

                  在Python3中

                  >>> L=[
                  ... {'id':1,'name':'john', 'age':34},
                  ... {'id':1,'name':'john', 'age':34},
                  ... {'id':2,'name':'hanna', 'age':30},
                  ... ] 
                  >>> list({v['id']:v for v in L}.values())
                  [{'age': 34, 'id': 1, 'name': 'john'}, {'age': 30, 'id': 2, 'name': 'hanna'}]
                  

                  在Python2.5/2.6中

                  >>> L=[
                  ... {'id':1,'name':'john', 'age':34},
                  ... {'id':1,'name':'john', 'age':34},
                  ... {'id':2,'name':'hanna', 'age':30},
                  ... ] 
                  >>> dict((v['id'],v) for v in L).values()
                  [{'age': 34, 'id': 1, 'name': 'john'}, {'age': 30, 'id': 2, 'name': 'hanna'}]
                  

                  这篇关于独特词典列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)
                  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替换为非空值)
                  • <bdo id='nVChp'></bdo><ul id='nVChp'></ul>

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

                    2. <small id='nVChp'></small><noframes id='nVChp'>