python之 json里字典中的value去重
1 import simplejson as json 2 3 with open(r'C:\Users\Desktop\test.txt', 'r' ) as f1, open(r'C:\Users\Desktop\newtest.txt', 'w') as f2: 4 alist = [] 5 new_dict = {} 6 for i in f1.readlines(): 7 alist.append(json.loads(i)) 8 9 for i in range(len(alist)): 10 if not new_dict.has_key(alist[i]['key']): 11 new_dict[alist[i]['key']] = True 12 f2.writelines(json.dumps(alist[i])) 13 f2.write('\n')
欢迎指正……
2017-09-13