Created
July 3, 2014 00:55
-
-
Save BDFife/02a6c4741591255e3732 to your computer and use it in GitHub Desktop.
Python Shuffle Text
This file contains 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
#!/usr/bin/python | |
import sys | |
import random | |
text = sys.stdin.read() | |
text = text.split() | |
new_text = "" | |
for word in text: | |
#print str(len(word)) | |
if len(word) > 3: | |
if word[-1] in ",.!?-": | |
mumble = list(word[1:-2]) | |
random.shuffle(mumble) | |
new_word = (word[0] + ''.join(mumble) + word[-2:]) | |
new_text += (new_word + " " ) | |
else: | |
mumble = list(word[1:-1]) | |
random.shuffle(mumble) | |
new_word = (word[0] + ''.join(mumble) + word[-1]) | |
new_text += (new_word + " " ) | |
else: | |
#mumble = list(word) | |
#random.shuffle(mumble) | |
#new_word = ''.join(mumble) | |
#new_text += (new_word + " " ) | |
new_text += (word + " " ) | |
sys.stdout.write(new_text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment