首页 > 解决方案 > Python:从具有唯一字段的 JSON 对象列表中删除重复对象

问题描述

我使用 PyMongo 从 MongoDB 中检索了以下 JSON。某些字段filepath对于每个对象都是唯一的。

[
    {
        "_id": {
            "$oid": "614c342ad3c1c8e2945c8668"
        },
        "album": "Come Over When You're Sober, Pt. 2",
        // some other fields
        "filepath": "/music/.../....flac"
    },
    {
        // some other objects
    },
    {
        "_id": {
            "$oid": "614c342dd3c1c8e2945c8c8c"
        },
        "album": "Come Over When You're Sober, Pt. 2",
        // some other fields
        "filepath": "/videos/...mp3"
    }
]

我想通过检查每个对象的专辑字段来从此列表中删除重复项。

我怎样才能做到这一点?

标签: pythonjsonlistobjectduplicates

解决方案


推荐阅读