“Python Remova duplicatas da lista de dicta” Respostas de código

Python remova elementos repetidos da lista


# ----- Create a list with no repeating elements ------ #

mylist = [67, 7, 89, 7, 2, 7]
newlist = []

  for i in mylist: 
    if i not in newlist: 
        newlist.append(i)
Ana

Python dict remove duplicatas onde o nome não é o mesmo

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)
Good Grouse

Python Remova duplicatas da lista de dicta

# 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)))))
gdfelt

Respostas semelhantes a “Python Remova duplicatas da lista de dicta”

Perguntas semelhantes a “Python Remova duplicatas da lista de dicta”

Mais respostas relacionadas para “Python Remova duplicatas da lista de dicta” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código