0

The 'id' is unique in each dict.

dict_list = []

a = {'id':1, 'b':2}
b = {'id':1, 'b':2}
c = {'id':2, 'b':2, 'c':2}

dict_list.append(a)
dict_list.append(b)
dict_list.append(c)

print(dict_list)

dict_list = list({d['id']: d for d in dict_list}.values())

print(dict_list)

Is there a better way to remove duplicates from the list?

marlon
  • 4,279
  • 6
  • 29
  • 49

0 Answers0