列表套字典,将字典元素去重

a = [{'name':'lilei','age':'18'},{'name':'tom','age':'18'},{'name':'lilei','age':'20'}]
b={}
for item in a:
b.setdefault(item['name'],{**item,})

b = list(b.values())

print(b)

原文地址:https://www.cnblogs.com/mqhpy/p/12985732.html