Skip to content

Instantly share code, notes, and snippets.

@Xion Xion/scramble.py
Last active Oct 11, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.