Skip to content

Instantly share code, notes, and snippets.

@HarryR
Created November 8, 2019 14:58
Show Gist options
  • Save HarryR/6c7512fd2ba4eac3a10fe4203fa00b2d to your computer and use it in GitHub Desktop.
Save HarryR/6c7512fd2ba4eac3a10fe4203fa00b2d to your computer and use it in GitHub Desktop.
Text to old-school phone keyboard
def text2sms(text):
pairs = [' ', '!', 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqrs', 'tuv', 'wxyz']
mapping = {c:(str(i)*(j+1)) for i,p in enumerate(pairs) for j, c in enumerate(p)}
return '-'.join(mapping[c] for c in text if c in mapping)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment