Remove duplicates from a list of nested dictionaries

Posted by user2924306 on Stack Overflow See other posts from Stack Overflow or by user2924306
Published on 2013-10-27T03:40:19Z Indexed on 2013/10/27 3:53 UTC
Read the original article Hit count: 207

Filed under:
|
|

I'm writing my first python program to manage users in Atlassian On Demand using their RESTful API. I call the users/search?username= API to retrieve lists of users, which returns JSON. The results is a list of complex dictionary types that look something like this:

[
        {
            "self": "http://www.example.com/jira/rest/api/2/user?username=fred",
            "name": "fred",
            "avatarUrls": {
                "24x24": "http://www.example.com/jira/secure/useravatar?size=small&ownerId=fred",
                "16x16": "http://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=fred",
                "32x32": "http://www.example.com/jira/secure/useravatar?size=medium&ownerId=fred",
                "48x48": "http://www.example.com/jira/secure/useravatar?size=large&ownerId=fred"
            },
            "displayName": "Fred F. User",
            "active": false
        },
        {
            "self": "http://www.example.com/jira/rest/api/2/user?username=andrew",
            "name": "andrew",
            "avatarUrls": {
                "24x24": "http://www.example.com/jira/secure/useravatar?size=small&ownerId=andrew",
                "16x16": "http://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=andrew",
                "32x32": "http://www.example.com/jira/secure/useravatar?size=medium&ownerId=andrew",
                "48x48": "http://www.example.com/jira/secure/useravatar?size=large&ownerId=andrew"
            },
            "displayName": "Andrew Anderson",
            "active": false
        }
    ]

I'm calling this multiple times and thus getting duplicate people in my results. I have been searching and reading but cannot figure out how to deduplicate this list. I figured out how to sort this list using a lambda function. I realize I could sort the list, then iterate and delete duplicates. I'm thinking there must be a more elegant solution.

Thank you!

© Stack Overflow or respective owner

Related posts about python

Related posts about list