Last active
October 11, 2015 00:18
-
-
Save Xion/3772973 to your computer and use it in GitHub Desktop.
Scrambling word letters in legible way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def scramble(text): | |
"""Scrambles the letters in given text, except for first | |
and last one in every word. | |
""" | |
words = text.split() | |
for i in xrange(words): | |
if len(words[i]) < 3: | |
continue | |
middle = list(words[i][1:-1]) | |
random.shuffle(middle) | |
words[i] = words[i][0] + "".join(middle) + words[i][-1] | |
return " ".join(words) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment