Last active
September 21, 2016 14:34
-
-
Save lovasoa/864e6724dd8e4c69408457ffe0bfdb59 to your computer and use it in GitHub Desktop.
Check spelling in a text file
This file contains hidden or 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
#!/usr/bin/env python3 | |
import sys, re | |
if len(sys.argv) not in (2,3): | |
sys.stderr.write("Usage: %s dictionnary.txt [file.txt]\n\nChecks spelling of text in input file.\n" % sys.argv[0]) | |
sys.exit(1) | |
infile = open(sys.argv[2]) if len(sys.argv)>2 else sys.stdin | |
inwords = set(map(str.lower, re.split("[^\\w]", infile.read()))) | |
with open(sys.argv[1]) as dictfile: | |
realwords = set() | |
for w in dictfile: realwords.add(w[:-1]) | |
for word in inwords - realwords: | |
print(word) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment