我有两个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等,但是我在这里可以找到的所有线程似乎都不是我正在寻找的。
在此先感谢!
如何列表合并? –