Horje
python dict remove duplicates where items are not the same Code Example
python dict remove duplicates where items are not the same
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)
python remove duplicates from list of dict
# set the dict to a tuple for hashability, then use {} for set literal and retrn each item to dict. 
[dict(t) for t in {tuple(d.items()) for d in l}]
# using two maps()
list(map(lambda t: dict(t), set(list(map(lambda d: tuple(d.items()), l)))))




Python

Related
how to get element from dictionary python Code Example how to get element from dictionary python Code Example
dataframe cut based on range Code Example dataframe cut based on range Code Example
python console width Code Example python console width Code Example
TypeError: Unicode-objects must be encoded before hashing Code Example TypeError: Unicode-objects must be encoded before hashing Code Example
python milisegundos Code Example python milisegundos Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7