📜  python dict 删除名称不同的重复项 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:19.781000             🧑  作者: Mango

代码示例2
import itertools
mylist = [{'x':2020 , 'y':20},{'x':2020 , 'y':30},{'x':2021 , 'y':10},{'x':2021 , 'y':5}]
mylist1=[]
for key, group in itertools.groupby(mylist,lambda x:x["x"]):
    max_y=0
    for thing in group:
        max_y=max(max_y,thing["y"])
    mylist1.append({"x":key,"y":max_y})
print(mylist1)