Skip to content

Instantly share code, notes, and snippets.

@zonble
Created April 9, 2016 15:09
Show Gist options
  • Save zonble/76f411a526b7b97875c63b440c41f70e to your computer and use it in GitHub Desktop.
Save zonble/76f411a526b7b97875c63b440c41f70e to your computer and use it in GitHub Desktop.
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