PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from random import shuffle
# [challenge] shuffle the middle of every word in a text
# https://www.sololearn.com/Discuss/1057287/challenge-shuffle-the-middle-of-every-word-in-a-text/
# by FarinHeiT
text = 'This is Sololearn'
def swap(text):
newText = ''
for word in text.split(' '):
if len(word) <= 3:
newText += word + ' '
else:
part = list(word[1:len(word) - 1])
shuffle(part)
newText += word[0] + ''.join(part) + word[-1] + ' '
return newText
print(swap(text))
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run