Last active
August 29, 2015 14:10
-
-
Save icedraco/8a650f9628e726357f5c to your computer and use it in GitHub Desktop.
A word scrambler script that keeps the first and the last letter in each word intact, and shuffles the letters in the middle. A person can often read the scrambled words just fine without realizing it.
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
| from sys import argv | |
| from random import shuffle | |
| def scrambleWord(w): | |
| i = len(w) - 1 | |
| # If it's a zero-length string, return it right away. | |
| if i < 0: | |
| return w | |
| else: | |
| # Handle non-alphabetical characters after the word/ | |
| while not w[i].isalpha() and i >= 0: | |
| i -= 1 | |
| # If the word itself is 3 bytes or less, don't bother. | |
| if i < 3: | |
| return w | |
| # Scramble & return | |
| gutter = list( w[1:i] ) | |
| shuffle(gutter) | |
| return w[0] + "".join(gutter) + w[i:] | |
| def scrambleSentance(s): | |
| # Split ever word by space and pass them all through scrambleWord(). | |
| return " ".join( map( scrambleWord, s.split(' ') ) ) | |
| if len(argv) > 1: | |
| print scrambleSentance(argv[1]) | |
| else: | |
| print "Syntax: %s <sentence>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment