Files
CoolProp/dev/mixtures/remove_dupes.py
Matthis Thorade 526cb198a4 autopep8 whitespace (#1613)
* autopep8 whitespace only:

--select="E101,W1,W2"

* revert single file: web2py_online.py

Should this be a .py file at all?

* revert file Tickets/1443.py because the diff looked strange:

maybe there is an encoding problem?

* Rename web2py_online.py to web2py_online.rst
2017-12-12 08:32:38 -07:00

35 lines
999 B
Python

import json
jj = json.load(open('mixture_binary_pairs.json','r'))
CASpairs = [tuple(sorted([p['CAS1'], p['CAS2']])) for p in jj]
dupes = {}
for unique in set(CASpairs):
if CASpairs.count(unique) > 1:
dupes[unique] = CASpairs.count(unique)-1 # number to remove
dupe_pairs = []
for i in range(len(jj)-1, -1, -1):
pair = tuple(sorted([jj[i]['CAS1'], jj[i]['CAS2']]))
if pair in dupes:
dupe_pairs.append(jj.pop(i))
dupes[pair] -= 1
if dupes[pair] == 0:
dupes.pop(pair)
with open('old_BIP.json','w') as fp:
fp.write(json.dumps(dupe_pairs, indent = 2, sort_keys = True))
with open('mixture_binary_pairs.json','w') as fp:
fp.write(json.dumps(jj, indent = 2, sort_keys = True))
jj = json.load(open('mixture_binary_pairs.json','r'))
CASpairs = [(p['CAS1'], p['CAS2']) for p in jj]
dupes = {}
for unique in set(CASpairs):
if CASpairs.count(unique) > 1:
dupes[unique] = CASpairs.count(unique)-1 # number to remove
print dupes