Skip to content

Instantly share code, notes, and snippets.

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