Python Scrambler Program
<p>This program takes words in a sentence and scrambles them.
The rules are:
- first and last letter remain the same
- punctuation at the end of a word stays the same
- punctuation with a word is scrambled like the middle letters</p>

<p>My problem is that if I have multiple punctuation at the end of a word it does not scramble it.</p>

<p>Ex) testing!!! should be something like t!ste!nig! or t!est!nig!
but not tstenig!!!</p>

<p>How can I fix that?</p>

<pre><code>import random
import string

original_text = input("Enter your text: ").split(' ')
seed = int(input("Enter a seed (0 for random): "))

punctuation = []
for c in string.punctuation:
    punctuation.append(c)

if seed is not 0:
    random.seed(seed)

randomized_list = []

def scramble_word(word):
    alpha = word[0]
    end_punctuation = ''

    if word[-1] in punctuation:
        x = -1
        while word[x] in punctuation:
            end_punctuation += word[x]
            x -= 1
        omega = word[x]
        middle = word[1: x]
    else:
        omega = word[-1]
        middle = word[1:-1]
        end_punctuation = ""
    middle_list = list(middle)
    random.shuffle(middle_list)
    shuffled_text = "".join(middle_list)
    new_words = alpha + shuffled_text + omega + end_punctuation
    return new_words
for item in original_text:
    if len(item) &lt;= 3:
        randomized_list.append(item)
    else:
        randomized_list.append(scramble_word(item))
new_words = " ".join(randomized_list)
print(new_words)
</code></pre>

<p>My take on it, can shorten the code a bit. (In Python 3.5.1)</p>

<pre><code>import random

words = input("Enter your text: ")

def scramble(words):
    for x in words.split():
        middle = x[1:-1]
        middle_list = list(middle)
        random.shuffle(middle_list)
        shuffled = "".join(middle_list)
        print ("".join(x[0]+shuffled+x[-1]),"", end="")


scramble(words)
</code></pre>

<p>My output was for example from:</p>

<p>Masterson!!%&amp; makes baking%$ potatoes great!</p>

<p>to
Ment!osrs!a%&amp; mkeas bigkna%$ patooets gerat! </p>

<p>I'm sure someone could shorten it even more dramatically.</p>

python python-3.x