我有一個如下所示的字典列表。基於某個鍵/值合併/總結一系列字符
[
{"value1": 53, "day": "Thu, 07 May 2015", "value2": 70, "type_of": "foo"},
{"value1": 17, "day": "Thu, 07 May 2015", "value2": 12, "type_of": "foo"},
{"value1": 21, "day": "Thu, 12 May 2013", "value2": 40, "type_of": "foo"}
]
現在,我想這對在求和"value1"
/"value2"
鍵和離開單獨"type_of"
的方式"day"
鍵相同的值類型的字典結合起來。
下面是我想要的結果:
[
{"value1": 70, "day": "Thu, 07 May 2015", "value2": 82, "type_of": "foo"},
{"value1": 21, "day": "Thu, 12 May 2013", "value2": 40, "type_of": "foo"}
]
那你試試這麼遠嗎? – Tryph
如果它們具有相同的日期值但type_of值不同,該怎麼辦?你保留哪一個? –
@ Farhan.K我們可以假定type_of總是「foo」。 –