我有一個指定流的跳轉列表(源跳轉到與他們各自的體積destionation)。 現在我想分割這些流到鏈接(例如(來源跳與音量,跳到目的地與音量),併合並所有重複的鏈接在一起,總結他們的體積Python減少基於匹配鍵/值對的Dicts列表
因爲我是新來的蟒蛇我'我想知道一個好的方法是什麼,我的第一種方法是循環遍歷所有的流程,並在內部的所有鏈接中嵌套一個循環,並檢查鏈接是否已經存在
但是,如果我有數以百萬計的流量,
我的起始資料看起來像這樣:
flows = [
{
'source': 1,
'hop': 2,
'destination': 3,
'volume': 100,
},{
'source': 1,
'hop': 2,
'destination': 4,
'volume': 50,
},{
'source': 2,
'hop': 2,
'destination': 4,
'volume': 200,
},
]
什麼我的結果應該是:
links = [
{
'source': 1,
'hop': 2,
'volume': 150,
},{
'hop': 2,
'destination': 3,
'volume': 100,
},{
'hop': 2,
'destination': 4,
'volume': 250,
},{
'source': 2,
'hop': 2,
'volume': 200,
},
]
非常感謝您的幫助!
[python pandas](http://pandas.pydata.org/)是你的朋友 – Craicerjack