0

I am trying to have the same behaviour, but I want to check if url dict contains unique values instead of checking the complete dict.

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, CA",
         "company":"rockstar",
         "date":{ 
            "display":"24 days ago",
            "timestamp":1570721082
         },
         "game":"akak2kak",
         "challenge":"leel",
         "url":"https://www.game.com/12757a575/aaashs/2222"
      }
   ]
}

print(unique(games))

I expect the output of "url":"https://www.game.com/12757a575/aaashs/2222" without having the same value in the same key

Aron Imperial
  • 99
  • 1
  • 1
  • 7

1 Answers1

0

How about creating a seprate list of urls to keep track of each unique url like so:

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
Kind Stranger
  • 1,736
  • 13
  • 18