我正在编写我的第一个 python 程序来使用他们的 RESTful API 在 Atlassian On Demand 中管理用户。我调用 users/search?username= API 来检索返回 JSON 的用户列表。结果是一个复杂的字典类型列表,如下所示:
[
{
"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
}
]
我多次调用它,从而在我的结果中得到重复的人。我一直在搜索和阅读,但无法弄清楚如何删除此列表的重复数据。我想出了如何使用 lambda 函数对该列表进行排序。我意识到我可以对列表进行排序,然后迭代并删除重复项。我认为必须有一个更优雅的解决方案。
谢谢!