我有一个类似于这个的字典列表:
{'Catch': 4.414, 'ShipID': 173, 'Name': u'Sigur\xf0ur \xd3lafsson SF - 44', 'Gear': u'BOTN'}
{'Catch': 2.401, 'ShipID': 173, 'Name': u'Sigur\xf0ur \xd3lafsson SF - 44', 'Gear': u'BOTN'}
{'Catch': 67.463, 'ShipID': 1275, 'Name': u'J\xf3n V\xeddal\xedn VE - 82', 'Gear': u'BOTN'}
{'Catch': 51.803, 'ShipID': 1275, 'Name': u'J\xf3n V\xeddal\xedn VE - 82', 'Gear': u'BOTN'}
{'Catch': 7.539, 'ShipID': 1595, 'Name': u'Fr\xe1r VE - 78', 'Gear': u'BOTN'}
{'Catch': 97.984, 'ShipID': 1903, 'Name': u'\xdeorsteinn \xdeH - 360', 'Gear': u'BOTN'}
{'Catch': 94.796, 'ShipID': 1903, 'Name': u'\xdeorsteinn \xdeH - 360', 'Gear': u'BOTN'}
{'Catch': 61.347, 'ShipID': 2020, 'Name': u'Su\xf0urey VE - 12', 'Gear': u'BOTN'}
{'Catch': 21.135, 'ShipID': 2401, 'Name': u'\xde\xf3runn Sveinsd\xf3ttir VE - 401', 'Gear': u'BOTN'}
{'Catch': 16.151, 'ShipID': 2444, 'Name': u'Vestmannaey VE - 444', 'Gear': u'BOTN'}
{'Catch': 41.213, 'ShipID': 2677, 'Name': u'Bergur VE - 44', 'Gear': u'BOTN'}
{'Catch': 5.046, 'ShipID': 2403, 'Name': u'Hvanney SF - 51', 'Gear': u'NET'}
{'Catch': 2.311, 'ShipID': 2403, 'Name': u'Hvanney SF - 51', 'Gear': u'NET'}
{'Catch': 6.304, 'ShipID': 2403, 'Name': u'Hvanney SF - 51', 'Gear': u'NET'}
{'Catch': 4.231, 'ShipID': 2732, 'Name': u'Skinney SF - 20', 'Gear': u'NET'}
{'Catch': 6.46, 'ShipID': 2732, 'Name': u'Skinney SF - 20', 'Gear': u'NET'}
...
此列表已预先排序:
list_sorted = sorted(landingList, key=lambda d:(d['Gear'], d['ShipID']))
这是冰岛船只登陆的列表,我想做的是将列表按“Gears”拆分并添加捕获量,以便显示总捕获量。与此类似
'BOTN' 列表如下所示:
{'Catch': 6.815, 'ShipID': 173, 'Name': u'Sigur\xf0ur \xd3lafsson SF - 44', 'Gear': u'BOTN'}
{'Catch': 119.266, 'ShipID': 1275, 'Name': u'J\xf3n V\xeddal\xedn VE - 82', 'Gear': u'BOTN'}
{'Catch': 7.539, 'ShipID': 1595, 'Name': u'Fr\xe1r VE - 78', 'Gear': u'BOTN'}
{'Catch': 192.78, 'ShipID': 1903, 'Name': u'\xdeorsteinn \xdeH - 360', 'Gear': u'BOTN'}
{'Catch': 61.347, 'ShipID': 2020, 'Name': u'Su\xf0urey VE - 12', 'Gear': u'BOTN'}
{'Catch': 21.135, 'ShipID': 2401, 'Name': u'\xde\xf3runn Sveinsd\xf3ttir VE - 401', 'Gear': u'BOTN'}
{'Catch': 16.151, 'ShipID': 2444, 'Name': u'Vestmannaey VE - 444', 'Gear': u'BOTN'}
{'Catch': 41.213, 'ShipID': 2677, 'Name': u'Bergur VE - 44', 'Gear': u'BOTN'}
那么“NET”列表将是这样的:
{'Catch': 13.661, 'ShipID': 2403, 'Name': u'Hvanney SF - 51', 'Gear': u'NET'}
{'Catch': 10.691, 'ShipID': 2732, 'Name': u'Skinney SF - 20', 'Gear': u'NET'}
当然还有更多的齿轮和着陆。但这只是为了演示列表的外观和我手头的任务。你能帮我解决这个问题吗?