Problem

Scrambled EnglishRead the following paragraph as quickly as you can and see if you encount...

Scrambled English

Read the following paragraph as quickly as you can and see if you encounter any difficulties.

Aoccdrnig to rscheearch at an Elingsh uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and lsat ltteer is at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit a porbelm. Tihs is bcuseae we do not raed ervey lteter by itslef but the wrod as a wlohe.

This paragraph was published as an example of a principle of human reading comprehension. If you keep the first letter and the last letter of a word in their correct positions and scramble the letters in between, the word is still quite readable in the context of a surrounding paragraph. However, it seems that this is a bit of a myth and not truly based on solid research. It turns out that for longer words, the task is much more difficult. Nonetheless, we are going to imitate the process on some English text.

Handling punctuation is tricky. You need to deal with punctuation that comes at the end of a word: comma, period, question mark, exclamation, etc. For example, in the previous sample, the word university ends with a comma, so you need to ensure that you do not treat the comma as the “last letter of the word” when you scramble all but the first and last letters.

Hints:

• Don’t bother trying to scramble words fewer than four characters long.

• The string split method is useful to create a list of words from a string of words.

• The string strip method is useful to remove end-of-line characters and other whitespace.

• To scramble a string, convert it to a list, use random.shuffle from the random module to scramble the string, and then use the join string method to convert back to a string: " .join(list)

(a) A simple way to get some text to work with is to simply put it in a long string. (Note the backslash continuation character: \)

               text = "Four score and seven years ago \                       our fathers brought forth \                       on this continent a new nation,"

(b) Alternatively, you could use a modification of the word-list driver from the word puzzle programming project above to read a file. To read a file named someFile.txt into one long string:

def getWordString():    dataFile = open("someFile.txt","r")    wordString = "	       # start with an empty string of words    for line in dataFile:       wordString += line      # add each line of words to the word string    return wordString

(c) Optionally, add the capability to handle punctuation in the middle of words, e.g., a hyphen in a word. Scramble on either side of the hyphen.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT