I'm creating an Anagram Solver in Python 2.7.
The solver takes a user inputted anagram, converts each letter to a list item and then checks the list items against lines of a '.txt' file, appending any words that match the anagram's letters to a possible_words
list, ready for printing.
It works... almost!
# Anagram_Solver.py
anagram = list(raw_input("Enter an Anagram: ").lower())
possible_words = []
with file('wordsEn.txt', 'r') as f:
for line in f:
if all(x in line + '\n' for x in anagram) and len(line) == len(anagram) + 1:
line = line.strip()
possible_words.append(line)
print "\n".join(possible_words)
For anagrams with no duplicate letters it works fine, but for words such as 'hello', the output contains words such as 'helio, whole, holes', etc, as the solver doesn't seem to count the letter 'L' as being 2 separate entries?
What am I doing wrong? I feel like there is a simple solution that I'm missing?
Thanks!