remove duplicates python
mylist = ["a", "b", "a", "c", "c"]
mylist = list(dict.fromkeys(mylist))
remove duplicates python
mylist = ["a", "b", "a", "c", "c"]
mylist = list(dict.fromkeys(mylist))
python dict remove duplicates where name 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)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us