Skip to content

Instantly share code, notes, and snippets.

@regakakobigman
Last active July 28, 2019 22:54
Show Gist options
  • Save regakakobigman/12dd636dd346777e9d2fc4717773e9e2 to your computer and use it in GitHub Desktop.
Save regakakobigman/12dd636dd346777e9d2fc4717773e9e2 to your computer and use it in GitHub Desktop.
Generate obnoxious numeronyms (like i18n for "Internationalization")
from typing import Pattern, Match
import re
# This pattern matches words separated by whitespace or hyphens.
_pattern: Pattern = r"([A-Za-z0-9']+)"
_regex: Match = re.compile(_pattern)
def obnoxiousify(text: str) -> str:
def repl(matchobj: Match) -> str:
word: str = matchobj.group(0)
if len(word) > 1:
# Example: "Internationalization" becomes "i18n"
word = (word[0] + str(len(word)) + word[-1]).lower()
return word
result: str = re.sub(_regex, repl, text)
return result
def main():
print(obnoxiousify("Howdy, ain't this nice and convenient?"))
print(obnoxiousify("There's nothing better than a nice cup of leetspeak-concentrate in the morning."))
# Output:
# "h5y, a5t t4s n4e a3d c10t?"
# "t7s n7g b6r t4n a n4e c3p o2f l9k-c11e i2n t3e m7g."
o12y, m4n = obnoxiousify, main # F3r c11e ¯\_(ツ)_/¯
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment