且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从字典列表中删除具有重复值的字典

更新时间:2023-01-17 18:58:11

如果顺序很重要,则可以使用

If the order matters, then you can use collections.OrderedDict to collect all the items, like this

from collections import OrderedDict
print OrderedDict((d["key"], d) for d in my_list).values()

如果顺序无关紧要,您可以使用像这样的普通词典

And if the order doesn't matter, you can use a normal dictionary, like this

print {d["key"]:d for d in my_list}.values()