Question: To do: This project focuses again on strings as well as introducing lists. Find the anagrams and print them. The Problem: An anagram, according to
To do: This project focuses again on strings as well as introducing lists.
Find the anagrams and print
them.
The Problem:
An anagram, according to the wikipedia, is:
a type of word play, the result of rearranging the letters of a word or phrase to produce a
new word or phrase, using all the original letters exactly once
(http://en.wikipedia.org/wiki/Anagram)
For example, the words canter, nectar, recant and trance are all anagrams of each other. That is,
exactly the same letters are in each word but in a different order, and each ordering of the letters
is a word in the English language.
You are going to write a program that reads from a word-list file (a file of words) and tries to
find all the anagrams of the user typed word. Your goal is to find the list of words that are
anagrams from a provided word-list.
Program Specifications
1.
Your program will read word from a data file (wordlist.txt) The word-list is formatted
to have one word on each line. cp $PUB/wordlist.txt wordlist.txt
2.
For a user interactive input, find all anagrams (some words have more than one, as the
above example showed) of that word.
3.
Output the anagram list.
Assignment Notes:
There are a couple of problems here. Think about each one before you start to program.
1.
How can I easily determine if two words are an anagram of each other? That is, what
simple process can I apply to the words and, as a result, know if those words are
anagrams? Note that the only characteristic that matters is what letters are in each word,
irrespective of order. Is there an arrangement of the letters that would make the (Also, see
the hint in note below!)
2.
Once I have such a process, how can I apply the process to all the words in the word-list
and then find all the words with the same anagram?
3.
It will be useful to convert a string to a list and a list to a string. Here are some idioms for
that:
myStr = bcad
myList = list(myStr)
# produces list [b,c,a, d]
# So here is the big clue! Ready? If I take a word (a string) and turn that word into a list,
#what operation can I apply with that list that I cant to the word as a string
myList.sort() # produces list [a,b,c,d]
So here is the big clue! Ready? If I take a word (a string) and turn that word into a list,
what operation can I apply with that list that I cant to the word as a string, and which
would be most helpful for anagram representation? Think!
sample output:
word for anagram search ?
slit <- user input in bold
Anagram for slit is(are):
list
silt
slit
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
