Remove duplicates from a list of nested dictionaries

bschulz

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!

Free Monica Cellio

The usernames are unique, right?

Does it have to be a list? Seems like an easy solution would be to make it a dict of dicts instead. Use the usernames as keys, and only the most recent version will be present.

If the values have to be ordered, there is an OrderedDict type you could look into: http://docs.python.org/2/library/collections.html#collections.OrderedDict

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

remove duplicates by key from nested list of objects of custom dictionaries

Remove duplicates dictionaries from list of dictionaries in python

Remove duplicates from a nested list

Remove duplicates key from list of dictionaries python

Remove duplicates from the list of dictionaries (with a unique value)

Remove duplicates values from list of dictionaries in python

How to efficiently remove duplicates from list of lists (nested) containing dictionaries and integers?

Remove duplicate values from list of nested dictionaries

How to remove duplicates from a list of nested objects?

Remove consecutive duplicates from nested list in Python?

Remove duplicates in a nested list

Python Remove duplicates from list of dictionaries based on a value

Remove duplicates from nested list using list as keys

Remove string after a predefined string from a nested list of dictionaries with pandas

How match data in list of dictionaries and remove duplicates?

Remove Duplicates from 3 deep nested list - python - sympy

Need to remove duplicates from a nested list preserving the order

Making a nested dictionaries from a list of dictionaries

How to remove subset dictionaries from list of dictionaries

Removing duplicates in nested dictionaries

remove (and count) duplicates from a list

How to remove duplicates from a list?

Remove Duplicates from List of String

Remove duplicates from subsequences of the list

Remove duplicates from dropdown list

Elixir Remove Duplicates From List

Remove duplicates from a Java List

Remove duplicates from List(Of T)

Remove duplicates from list of object