I am trying to print only words that match the regex I provide and only contain the letters provided in the second parameter. The regex works perfectly, but the letter selection does not.
import re
def search(regex,letters):
letters=set(letters)
pattern=re.compile(regex)
for word in content:
word=word.strip()
if(pattern.findall(word)):
if letters & set(word):
print(word)
#search(r'^(n|u|p|g|o|u|e|b|l){6}$')
#search(r'^t(i|a)[a-z]{3}')
content=["hello","helps","halts","random"]
search(r'^h(e|a)[a-z]{3}','hltsa') #returns: hello,helps,halts
My goal is to get this to return only halts, because it matches the second parameter.