Fairly new to Python but I'm trying to make a Scrabble anagram solver which will loop through a large text file and check for anagrams with a user given 7 letter rack. I'm working on the is_anagram
function and using sorted()
to make a list of the letters in the word in alphabetical order and then using a if
statement to see if the sorted word from the dictionary is equal to the sorted rack of letters provided. Because the letters that are being searched come from a long list there is a "\n"
in the list created from the words which makes it so they are not equal. I'm trying to set up the iteration so that it removes '\n'
from the list before comparing it ,but for some reason it is returning the list as None
instead of the list minus '\n'
. Not sure why. Anyone can help? Code is below:
def is_anagram(word):
scrabble_dict = open('sowpods.txt')
for x in scrabble_dict:
x = sorted(x)
x = x.remove('\n')
word = sorted(word)
if word == x:
print(word)