import re # Load the lexicon resource with open('upperwords.txt') as f: lex=f.read() # Compile the pattern patt=re.compile(r'\bR...T\b') # Match pattern in lex res=patt.findall(lex) for word in res: print(word)