Question
Write a Python application, that is valid in Python 3, which uses recursion to generate all possible anagrams for a phrase taken from user input,
Write a Python application, that is valid in Python 3, which uses recursion to generate all possible anagrams for a phrase taken from user input, then prints those that consist only of valid English words. Treat blanks as characters; you do not need to generate anagrams that contain more or fewer blanks that are present in the input phrase. Convert all letters to lower case before you generate the anagrams. The output must not contain any duplicates.
Using a file named wordsEn.txt, as the source of the list of valid English words, compare each word in the anagram to a line, make sure that if any word in the created anagram is not found in the file it does not print.(Do not worry about the file itself just the name of the file) write code to read it in. Use an iterator to read one line at a time. Each line of the file contains one word. Strip any whitespace from each line and make sure you do not add any newlines to the word list. Use a simple driver script, an Anagramizer class, and a WordList class. WordList will need a contains() method, which determines whether a particular string is a valid word. This method should use binary, not linear, search (lists are implemented in CPython with arrays of pointers, so binary search of a list is O(log n)). Design the class so that you only sort the list *once*, after it is read in, not in the contains() method, which will be called many times.
Use this Pseudocode to generate the annograms recursively
if text.length == 1 return {letters} # Set containing one string. When created, the list will consist of one string with one letter, but it is a set of strings, not a set of chars. else ret = set() for each letter in the string anagramize the rest of the string
add to the set each of the anagrams prepended by the letter you left out return ret
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started