如何根据 api 响应创建列表并删除重复项

How to create a list from api reponse and remove duplicates

我想从 api json 响应中为 jira 中的每张工单制作一个列表,并删除任何重复项

我可以获取每张票的值,但无法将其作为列表并从中删除重复项以进行处理

这是每个工单的apijson响应

response = {
    "expand": "renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations",
    "id": "1831845",
    "self": "https://jira.com/login/rest/api/latest/issue/1845",
    "key": "pc-1002",
    "fields": {
                 "customfield_1925": {
                    "self": "https://jira.com/login/rest/api/2/customFieldOption/1056",
                    "value": "windows",
                    "id": "101056"
                }

所以我有这样的脚本:

import requests, json

tick = """jira: pc-1002,pc-1003,pc-1005
env"""
ticks = tick.replace(' ','').split(':')[1].split('\n')[0].split(',')
print(ticks)

for i in ticks:
    url = "https://jira.com/login/rest/api/latest/issue/" + str(i)
    print(url)

    response = requests.request("GET", url, verify=False)
    response = json.loads(response.text)
    resp = response['fields']['customfield_1925']['value']   
    print(resp)

所以它会打印如下所有值: 输出:

windows1 windows2 windows1

我希望输出值是唯一的,因为它最终可能会重复。

我想要如下输出

['windows1', 'windows2']

只需将每个响应添加到响应列表中,然后使用 Python 方便的 "in" 运算符检查每个响应是否已在列表中。大致如下:

    allResponses = []
    for i in ticks:
        url = "https://jira.com/login/rest/api/latest/issue/" + str(i)
        print(url)

        response = requests.request("GET", url, verify=False)
        response = json.loads(response.text)
        resp = response['fields']['customfield_1925']['value']
        if resp not in allResponses:   
            print(resp)
            allResponses.append(resp)