Python 有没有办法操纵(添加、删除)某些键并将所有值分组到一个键下?
在python中是否有一种通用的方法将值分组到同一个键Python 有没有办法操纵(添加、删除)某些键并将所有值分组到一个键下?,python,json,Python,Json,在python中是否有一种通用的方法将值分组到同一个键 for i in data: val.append(i[value]) 用python for i in data: val.append(i[value]) [{'indicator': {'id': 'PROT.MINOR.INV.EXT.OWNR.CONT.XD.0100.DB1519', 'value': 'Protecting minority investors: Extent of ownership a
for i in data:
val.append(i[value])
用python
for i in data:
val.append(i[value])
[{'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使用列表理解:
val = [i['value'] for i in data]
你是说
i['value']
?