How to parse JSON file into a list and remove duplicate objects in Python

1 Answer

0 votes
import json

with open('data.json') as f:
     urls = json.load(f)

uniqueURLs = { lst['url'] : lst for lst in urls }.values()
 
print(uniqueURLs)
 



'''
run:

dict_values([{'url': 'https://www.collectivesolver.com/'}, 
             {'url': 'https://www.collectivesolver.com/questions'}, 
             {'url': 'https://www.collectivesolver.com/tags'}, 
             {'url': 'https://www.collectivesolver.com/tag/python'}, 
             {'url': 'https://www.collectivesolver.com/tag/php'}, 
             {'url': 'https://www.collectivesolver.com/tag/java'}])

'''

 



answered Jun 18, 2020 by avibootz

Related questions

1 answer 169 views
1 answer 181 views
1 answer 154 views
154 views asked Jun 18, 2020 by avibootz
1 answer 163 views
163 views asked Feb 16, 2021 by avibootz
1 answer 197 views
197 views asked Feb 16, 2021 by avibootz
...