Skip to content

Instantly share code, notes, and snippets.

@xpe
Last active October 7, 2019 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xpe/85899a3ad361a3881aed7e75275ba9fa to your computer and use it in GitHub Desktop.
Save xpe/85899a3ad361a3881aed7e75275ba9fa to your computer and use it in GitHub Desktop.
Use this when your phrases need numeronyms!
def abbreviate(phrase):
def shorten(w, t=7):
if len(w) <= t:
return w
else:
return "{}{}{}".format(w[0], len(w)-2, w[-1])
return " ".join([shorten(w) for w in phrase.split(" ")])
abbreviate("The Heilmeier Catechism demands a thoughtful approach to risk taking")
# 'The H7r C7m demands a t8l a6h to risk taking'
@xpe
Copy link
Author

xpe commented Oct 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment