Last active
February 6, 2022 01:49
-
-
Save ThatCoolCoder/dd0a71e577649fcde1343223ff92183c to your computer and use it in GitHub Desktop.
Thnig that scrambles wdors eexpct for the fsirt and last ltteers. (tihs decrsiption is epaxlme opuutt)
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/python3 | |
# Example usage: cat in.txt | ./scrambler.py > out.txt | |
# echo "My text here" | ./scrambler.py | cat | |
import random | |
import string | |
import sys | |
def scramble_word(word: str): | |
if len(word) <= 3: | |
return word | |
else: | |
scrambled_middle = list(word[1:-1]) | |
random.shuffle(scrambled_middle) | |
return word[0] + ''.join(scrambled_middle) + word[-1] | |
def scramble_text(text: str): | |
text_sections = [] | |
crnt_word = '' | |
for char in text: | |
if char in string.ascii_letters: | |
crnt_word += char | |
else: | |
text_sections.append(crnt_word) | |
text_sections.append(char) | |
crnt_word = '' | |
return ''.join([scramble_word(section) for section in text_sections]) | |
if __name__ == '__main__': | |
print(scramble_text(''.join(sys.stdin))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment