-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_threes.py
More file actions
executable file
·42 lines (29 loc) · 941 Bytes
/
Copy pathimport_threes.py
File metadata and controls
executable file
·42 lines (29 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
import csv
import sys
import util
def output_word(word: str, score: int) -> None:
print(f"{util.normalize(word)};{score}")
def load_csv(fname: str) -> None:
wordlist = {}
with open(fname, newline='') as csvfile:
reader = csv.reader(csvfile, delimiter='\t')
# First header is just for notes in the doc
_ = next(reader)
# Second row gives scores
scores = next(reader)
for row in reader:
for word, score in zip(row, scores):
if word == '' or score == '':
continue
wordlist[word] = score
for word, score in sorted(wordlist.items()):
output_word(word, int(score))
def main(args: list[str]) -> None:
load_csv(args[0])
if __name__ == "__main__":
args = sys.argv
if len(args) < 2:
print("expected wordlist files to load")
exit(1)
main(args[1:])