[英]Remove duplicates from the list of dictionaries
我有以下词典列表:
d = [
{ 'name': 'test', 'regions': [{'country': 'UK'}] },
{ 'name': 'test', 'regions': [{'country': 'US'}, {'country': 'DE'}] },
{ 'name': 'test 1', 'regions': [{'country': 'UK'}], 'clients': ['1', '2', '5'] },
{ 'name': 'test', 'regions': [{'country': 'UK'}] },
]
从列表中删除重复条目的最简单方法是什么?
我看到了有效的解决方案,但前提是项目没有嵌套的dicts或列表
这个怎么样:
new_d = []
for x in d:
if x not in new_d:
new_d.append(x)
对于最容易实现的“易于实现”, 这个问题中的那个看起来非常紧凑。
尽管如此,它在性能方面也不太可能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.