[英]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.