我有兩個Python 2.6中的字典列表,我想根據與另一個鍵對應的一個鍵的最高值合併它們。該列表是這樣的:基於一個鍵/值對合並python詞典列表?
[{shape: square, color: red, priority: 2},
{shape: circle, color: blue, priority: 2},
{shape: triangle, color: green, priority: 2}]
[{shape: square, color: green, priority: 3},
{shape: circle, color: red, priority: 1}]
我想要得到這樣的輸出:(項目的順序並不重要)
[{shape: square, color: green, priority: 3},
{shape: circle, color: blue, priority: 2},
{shape: triangle, color: green, priority: 2}]
換句話說,我'想要通過這兩個列表並且獲得每個列表項目的'顏色','形狀'和'優先級'的字典,其中'形狀'的每個值的'優先'值是最高的)
我一直在尋找和在幾天的時間裏嘗試不同的事情,並且我終於讓步了。我已經嘗試過各種版本的max,key,lambda等,但是我在這裏可以找到的所有線程似乎都不是我正在尋找的。
在此先感謝!
如何列表合併? –