Skip to content

Instantly share code, notes, and snippets.

@Xion
Last active October 11, 2015 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xion/3772973 to your computer and use it in GitHub Desktop.
Save Xion/3772973 to your computer and use it in GitHub Desktop.
Scrambling word letters in legible way
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