Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [{"id":"1","name":"Paul","age":"21"},
- {"id":"2","name":"Peter","age":"22"},
- {"id":"3","name":"Paul","age":"23"}]
- [{"id":"1"."name":"Paul","age":"21"},
- {"id":"2","name":"Peter","age":"22"}]
- 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
- import json
- with open('python.json') as fp:
- ds = json.load(fp) #this file contains the json
- mem = {}
- for record in ds:
- name = record["name"]
- if name not in mem:
- mem[name] = record
- print mem.values()
- new = []
- seen = set()
- for record in old:
- name = record['name']
- if name not in seen:
- seen.add(name)
- new.append(record)
- del seen
- ds = [{"id":"1","name":"Paul","age":"21"},
- {"id":"2","name":"Peter","age":"22"},
- {"id":"3","name":"Paul","age":"23"}]
- {elem["name"]:elem for elem in ds}.values()
- Out[2]:
- [{'age': '23', 'id': '3', 'name': 'Paul'},
- {'age': '22', 'id': '2', 'name': 'Peter'}]
Add Comment
Please, Sign In to add comment