🛠️ToolsShed

Word Scrambler

Scramble the middle letters of words while keeping first and last letters intact.

WordScrambler.factTitle WordScrambler.factText

WordScrambler.howTitle

WordScrambler.howText

Questions Fréquentes

Implémentation du Code

import re
import random

def shuffle_middle(word: str) -> str:
    if len(word) <= 3:
        return word
    middle = list(word[1:-1])
    random.shuffle(middle)
    return word[0] + ''.join(middle) + word[-1]

def scramble_text(text: str) -> str:
    return re.sub(r"[a-zA-Z]+('s)?", lambda m: shuffle_middle(m.group()), text)

text = "The quick brown fox jumps over the lazy dog"
scrambled = scramble_text(text)
print("Original:", text)
print("Scrambled:", scrambled)
print()
print("Note: First and last letters are preserved.")
print("This is the Cambridge reading effect.")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.