# short function to easily find matches for crossword puzzles def match(): import re # get regular expression package from nltk_lite.corpora import words #list of 800+ common words wordlist = list(words.raw()) again = 'y' while again[0] != 'n': #check first letter of response pat = raw_input("Enter pattern without quotes: ") confirm = raw_input("Confirm: " + pat + " ?(y/n) ") if confirm[0] == 'y': # select the words that match the pattern result = [w for w in wordlist if re.match(pat + '$',w)] print str(len(result)) + " matches found." ct = raw_input("How many do you want to see? ") ct = int(ct) if ct > 0: print result[: ct] #illustrates use of a slice again = raw_input("Continue? (y/n) ") # Call match() if this file is executed at top level if __name__ == "__main__": match()