-
-
Save lukhnos/2d4c628e2690b5407777f2b75f699a89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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