To accomplish this, you will need a database of viable words. An english dictionary will do.
One way is to check for words in the database that are anagrams of the jumbled string. Here’s a naive algo: read the viable words into an appropriate data structure a python dict
or tuple
will suffice. Assume the viable words are stored in a list: wordlist
sort the jumbled word and compare it to each of the (sorted) words in wordlist in turn. Print each positive result.
A simple implementation will look like this:
sorted_jumbled_word = "".join(sorted(jumbled_word)) for word in wordlist: if sorted_jumbled_word == "".join(sorted(word)): print(word)
Note this is extremely inefficient (as it will search the entire list of viable words). You can use a dictionary of containing sorted words as keys and every possible anagram as the values. However this should get you started.