-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmisspellings.py
More file actions
30 lines (28 loc) · 749 Bytes
/
misspellings.py
File metadata and controls
30 lines (28 loc) · 749 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
#!/usr/bin/python3
import sys
import re
words = {}
for line in re.split(r'[\|\n]',sys.stdin.read()):
if (line):
line = re.sub("^[ \t\"\+]*", '', line)
line = re.sub("[ \t\"\+]*$", '', line)
if (re.search(":",line)):
(wrong, correct) = re.split(r':', line)
else:
correct = line
wrong = correct
correct = correct.strip()
if (correct):
if (correct not in words):
words[correct] = {}
for word in re.split(r',', wrong):
word = word.strip()
if (word and word != correct):
words[correct][word] = 1
for ms in sorted(words.items(), key=lambda s:s[0].casefold()):
rep = ",".join(sorted(ms[1], key=lambda s:s.casefold()))
if (rep == ms[0] or len(rep)==0):
mp = ms[0]
else:
mp = rep+ ":" + ms[0]
print(mp)