aboutsummaryrefslogtreecommitdiff
path: root/challenge-289/eric-cheung/python/ch-2.py
blob: 09f789c2a5c183ed803f550c2f6bf1583e42f7fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import random

def GetWordShuffle (strInput):
    arrChar = [nIndx for nIndx, charLoop in enumerate(strInput) if charLoop.isalpha()]

    arrSubChar = [nIndx for nIndx in arrChar[1:-1]]
    random.shuffle(arrSubChar)

    return strInput[:arrChar[0] + 1] + "".join([strInput[nIndx] for nIndx in arrSubChar]) + strInput[arrChar[-1]]

## strInput = "Perl"  ## Example 1
strInput = "According to a researcher (sic) at Cambridge University, it doesn't matter in what order the letters in a word are, the only important thing is that the first and last letter be at the right place. The rest can be a total mess and you can still read it without problem. This is because the human mind does not read every letter by itself but the word as a whole."  ## Example 2

strOutput = " ".join([GetWordShuffle(strLoop) for strLoop in strInput.split(" ")])

print (strOutput)