import re ########################################## # Version 3 - inputs pattern from user # ########################################## # Load the lexicon resource as a string with open('upperwords.txt') as f: lex=f.read() # Prompt for the pattern to match banner = ''' u3aTod Crossword Helper Helps you solve a crossword clue or a word in a codeword, When prompted, enter a pattern matching a partially-known answer. Type the letters you know, and write a dot in place of the letters you don't know. Example: ..T.O. which would match PYTHON. Max length 13 characters. ''' print(banner) user_pattern=input('Enter your crossword answer pattern: ') user_pattern=r'{}'.format("\\b"+user_pattern.upper()+"\\b") # Compile the pattern patt=re.compile(user_pattern) # Match pattern in lex res=patt.findall(lex) # Display matches, several to a line buffer='' for word in res: if(len(buffer))>60: print(buffer) buffer='' buffer+=word buffer+=' ' print(buffer)