Skip to content

Instantly share code, notes, and snippets.

@lukhnos
Created May 7, 2024 20:37
Show Gist options
  • Save lukhnos/2d4c628e2690b5407777f2b75f699a89 to your computer and use it in GitHub Desktop.
Save lukhnos/2d4c628e2690b5407777f2b75f699a89 to your computer and use it in GitHub Desktop.
with open("phrase.occ", "r") as f:
lines = f.readlines()
kvs = [line.strip().split() for line in lines]
kvs = [(k, int(v)) for k, v in kvs]
m = {}
for k, v in kvs:
if k not in m:
m[k] = v
else:
if v > m[k]:
m[k] = v
print("%s, existing: %d < testing: %d, picked" % (k, m[k], v))
else:
print("%s, existing: %d > testing: %d, ignored" % (k, m[k], v))
with open("phrase.occ.sorted", "w") as f:
for k in sorted(m.keys()):
f.write("%s %d\n" % (k, m[k]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment