""" make_words.py create words.txt from /usr/share/dict/words, leaving out (a) words with fewer than four letters, and (b) words with any characters other than lowercase a-z. """ import re # regular expressions lowercase = re.compile("[a-z]+") def valid(word): return lowercase.fullmatch(word) and len(word) > 4 def main(): from_file = open('/usr/share/dict/words', 'r') to_file = open('./words.txt', 'w') while True: word = from_file.readline().strip() if not word: return if valid(word): to_file.write(word + '\n') main()