removing json items from array if value is duplicate python
Question: I am incredibly new to python.

I have an array full of json objects. Some of the json objects contain
duplicated values. The array looks like this:

    
    
     [{"id":"1"."name":"Paul","age":"21"},
      {"id":"2","name":"Peter","age":"22"},
      {"id":"3","name":"Paul","age":"23"}]
    

What I am trying to do is to remove an item if the `name` is the same as
another json object, and leave the first one in the array.

So in this case I should be left with

    
    
      [{"id":"1"."name":"Paul","age":"21"},
      {"id":"2","name":"Peter","age":"22"}]
    

The code I currently have can be seen below and is largely [based on this
answer](http://stackoverflow.com/questions/17076345/remove-duplicates-from-
json-data):

    
    
    import json
    ds = json.loads('python.json') #this file contains the json
    unique_stuff = { each['name'] : each for each in ds }.values()
    
    all_ids = [ each['name'] for each in ds ]
    unique_stuff = [ ds[ all_ids.index(text) ] for text in set(texts) ]
    
    print unique_stuff
    

I am not even sure that this line is working `ds = json.loads('python.json')
#this file contains the json` as when I try and `print ds` nothing shows up in
the console.


Answer: If you need to keep the first instance of `"Paul"` in your data a dictionary
comprehension gives you the opposite result.

A simple solution could be as following

    
    
    new = []
    seen = set()
    for record in old:
        name = record['name']
        if name not in seen:
            seen.add(name)
            new.append(record)
    del seen
    

