Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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)
Comment

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)))))
Comment

remove duplicates in python dictionary

remove dduplicates python dict
Comment

PREVIOUS NEXT
Code Example
Python :: # remove punctuation 
Python :: user information in python 
Python :: python session set cookies 
Python :: how to calculate the variance of all columns in python 
Python :: keras conv2d batchnorm 
Python :: python get github file content 
Python :: python - how many letters are capital in a string 
Python :: python string cut last n characters 
Python :: length of list python 
Python :: pandas convert string column to int list column 
Python :: fetch row where column is missing pandas 
Python :: find optimal number of clusters sklearn 
Python :: one liner if else replacement in python 
Python :: get file in file zip python 
Python :: python delete directory contents 
Python :: pd.datafram 
Python :: check palindrome in python 
Python :: install python 3.8 on wsl 
Python :: how to check encoding of csv 
Python :: how to make text to speech in python 
Python :: open gui window python 
Python :: merge a list of dictionaries python 
Python :: python slit 
Python :: virtualenv 
Python :: python gui 
Python :: plt.hist using bins 
Python :: break while loop python 
Python :: install poetry on linux 
Python :: selenium get h1 text python 
Python :: reading a file line by line using a generator 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =