I'm trying to write a program which filters a word list by letters. The aim is to get the words that contain any of the letters given without other letters. Im trying to do it with the all() function in a list comprehesion. That doest work as I expect, because it's just filtering the words containing this set of letters but no excluding the rest of the alphabet:
letters = ['R', 'E', 'T', 'O', 'P', 'A']
letters = ['R', 'E', 'T', 'O', 'P', 'A']
final_list = [word for word in dictionary if all(word for letter in letters if letter in word)]
Does anybody have an idea of how to do that?
Thank you in advance!