Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago