Add main.py
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import sys
|
||||
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
sys.stdin.reconfigure(encoding="utf-8")
|
||||
except (AttributeError, ValueError):
|
||||
pass
|
||||
|
||||
RLE = ""
|
||||
ALM = ""
|
||||
PUNCTUATION = "!?.,;:…"
|
||||
|
||||
|
||||
def transform(message):
|
||||
trailing = ""
|
||||
while message and message[-1] in PUNCTUATION:
|
||||
trailing = message[-1] + trailing
|
||||
message = message[:-1]
|
||||
if "|" in message:
|
||||
head, _, tail = message.partition("|")
|
||||
body = head + RLE + trailing + RLE + RLE + tail.replace("|", RLE)
|
||||
else:
|
||||
body = message + RLE + trailing + RLE + RLE
|
||||
return body + ALM + ALM + RLE
|
||||
|
||||
|
||||
while True:
|
||||
try:
|
||||
print(transform(input("> ")))
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
break
|
||||
Reference in New Issue
Block a user