首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法操作(添加、删除)某些键并将所有值分组到一个键下?

有没有办法操作(添加、删除)某些键并将所有值分组到一个键下?
EN

Stack Overflow用户
提问于 2019-09-12 13:49:59
回答 1查看 19关注 0票数 0

在python中,有没有一种通用的方法将值分组到同一个键中?

代码语言:javascript
复制
for i in data:
   val.append(i[value])

在python中

代码语言:javascript
复制
[{'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': '5',
  'decimal': '1',
  'date': '2019'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': '5',
  'decimal': '1',
  'date': '2018'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': '5',
  'decimal': '1',
  'date': '2017'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': '5',
  'decimal': '1',
  'date': '2016'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': '5',
  'decimal': '1',
  'date': '2015'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': '5',
  'decimal': '1',
  'date': '2014'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': None,
  'decimal': '1',
  'date': '2013'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': None,
  'decimal': '1',
  'date': '2012'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': None,
  'decimal': '1',
  'date': '2011'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': None,
  'decimal': '1',
  'date': '2010'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': None,
  'decimal': '1',
  'date': '2009'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': None,
  'decimal': '1',
  'date': '2008'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': None,
  'decimal': '1',
  'date': '2007'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': None,
  'decimal': '1',
  'date': '2006'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': None,
  'decimal': '1',
  'date': '2005'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'GB', 'value': 'United Kingdom'},
  'value': None,
  'decimal': '1',
  'date': '2004'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': '4.4',
  'decimal': '1',
  'date': '2019'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': '4.4',
  'decimal': '1',
  'date': '2018'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': '4.4',
  'decimal': '1',
  'date': '2017'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': '4.4',
  'decimal': '1',
  'date': '2016'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': '4.4',
  'decimal': '1',
  'date': '2015'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': '4.4',
  'decimal': '1',
  'date': '2014'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': None,
  'decimal': '1',
  'date': '2013'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': None,
  'decimal': '1',
  'date': '2012'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': None,
  'decimal': '1',
  'date': '2011'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': None,
  'decimal': '1',
  'date': '2010'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': None,
  'decimal': '1',
  'date': '2009'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': None,
  'decimal': '1',
  'date': '2008'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': None,
  'decimal': '1',
  'date': '2007'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': None,
  'decimal': '1',
  'date': '2006'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': None,
  'decimal': '1',
  'date': '2005'},
 {'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519',
   'value': 'Protecting minority investors: Extent of ownership and control index (0-10) (DB15-19 methodology)'},
  'country': {'id': 'US', 'value': 'United States'},
  'value': None,
  'decimal': '1',
  'date': '2004'}]

1

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-12 13:56:53

使用列表理解:

代码语言:javascript
复制
val = [i['value'] for i in data]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57900436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档