Learning Scientific Programming with Python (2nd edition)
P2.5.11: Jumbling the letters in each word of a sentence
Question P2.5.11
Write a program to take a string of text (words, perhaps with punctuation, separated by spaces) and output the same text with the middle letters shuffled randomly. Keep any punctuation at the end of words. For example, the string:
Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal.
might be rendered:
Four sorce and seevn yeras ago our fhtaers bhrogut ftroh on this cnnoientt a new noitan, cvieecond in lbrteiy, and ddicetead to the ptosoiporin that all men are cetaerd euaql.
Hint: random.shuffle
shuffles a list
of items in place. See Section 4.5.1 of the book.