I'm trying to find a simple way to solve an anagram and display those anagrams that are English words on the return page. Currently this shows the permutations on the solver page and somewhat works but I'd like to show those that are actual words only.
Any advice is greatly appreciated.
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'GET':
return render_template('main.html')
else:
myLetters = request.form['letters']
myLetters = ''.join(sorted(myLetters))
myLetters = myLetters.strip()
myWords = []
myLetterList = list(myLetters)
lettersLength = len(myLetterList)
myWords = [''.join(result) for result in permutations(myLetters)]
with open("/usr/share/dict/words") as defaultWords:
for word in myWords:
if word not in defaultWords:
myWords.remove(word)
return render_template('solver.html', myLetters = myLetters, myWords = myWords)