在python中,有没有一种通用的方法将值分组到同一个键中?
for i in data:
val.append(i[value])在python中
[{'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
发布于 2019-09-12 13:56:53
使用列表理解:
val = [i['value'] for i in data]https://stackoverflow.com/questions/57900436
复制相似问题