Skip to content

Instantly share code, notes, and snippets.

@lovasoa
Last active September 21, 2016 14:34
Show Gist options
  • Save lovasoa/864e6724dd8e4c69408457ffe0bfdb59 to your computer and use it in GitHub Desktop.
Save lovasoa/864e6724dd8e4c69408457ffe0bfdb59 to your computer and use it in GitHub Desktop.
Check spelling in a text file
#!/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