with open("fiveletterwords.txt") as f:
lines = f.readlines()
lines = [word.strip('\n') for word in lines]
lines[:10]
['aaron', 'ababa', 'abaci', 'aback', 'abaft', 'abase', 'abash', 'abate', 'abbey', 'abbot']
frequencies = {}
for word in lines:
for letter in word:
if not letter in frequencies:
frequencies[letter]=0
frequencies[letter]+=1
frequencies = list(frequencies.items())
frequencies.sort(key=lambda x : x[1], reverse=True)
frequencies[:10]
[('e', 3042), ('s', 2955), ('a', 2476), ('r', 1897), ('o', 1842), ('i', 1705), ('l', 1643), ('t', 1570), ('n', 1364), ('d', 1133)]
words = [word for word in lines if all(l in word for l, _ in frequencies[:5])]
words
['arose']