我怎样才能只检查一个专用字典键的唯一值?

我正在尝试具有相同的行为,但是我想检查url字典是否包含唯一值,而不是检查完整的字典。

def unique(data):
    result = {}
    for key,value in data.items():
        new_list = []
        for item in value:
            if item not in new_list:
                new_list.append(item)
        result[key] = new_list
        return result



games = { 
   "games":[ 
      { 
         "city":"Santa Monica,CA","company":"rockstar","date":{ 
            "display":"24 days ago","timestamp":1570721082
         },"game":"akakkak","challenge":"leel","url":"https://www.game.com/12757a575/aaashs/2222"
      },{ 
         "city":"Santa Monica,"game":"akak2kak","url":"https://www.game.com/12757a575/aaashs/2222"
      }
   ]
}

print(unique(games))

我希望"url":"https://www.game.com/12757a575/aaashs/2222"的输出在同一键中没有相同的值

dalaoer007 回答:我怎样才能只检查一个专用字典键的唯一值?

如何创建一个单独的网址列表来跟踪每个唯一的网址,如下所示:

def unique(data):
    result = {}
    for key,value in data.items():
        new_list = []
        url_list = []
        for item in value:
            if item['url'] not in url_list:
                new_list.append(item)
                url_list.append(item['url'])
        result[key] = new_list
        return result
本文链接:https://www.f2er.com/3169559.html

大家都在问