Skip to content

Instantly share code, notes, and snippets.

@BDFife
Created July 3, 2014 00:55
Show Gist options
  • Save BDFife/02a6c4741591255e3732 to your computer and use it in GitHub Desktop.
Save BDFife/02a6c4741591255e3732 to your computer and use it in GitHub Desktop.
Python Shuffle Text
#!/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