Created
April 9, 2016 15:09
-
-
Save zonble/76f411a526b7b97875c63b440c41f70e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
MAP = {",": ".", "!": "?", "(": ")", "{": "}", "[": "]", "<": ">", "@": "#", | |
";": ":", ".": ",", "?": "!", ")": "(", "}": "{", "]": "[", ">": "<", | |
"#": "@", ":": ";"} | |
c_t = lambda x: ''.join(c.swapcase() for c in x.group(0)[::-1]) | |
def twist(text): | |
import re | |
text = re.sub(r'[a-zA-Z]*', c_t, text) | |
text = re.sub(r'\s+', ' ', text) | |
text = re.sub(r'[0-9]', lambda x: str(9 - int(x.group(0))), text) | |
text = re.sub('[!#$%&()*+,-./:;<=>?@[\]^_`{|}~]', | |
lambda x: MAP.get(x.group(0), x.group(0)), text) | |
return text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment