Created
November 8, 2019 14:58
-
-
Save HarryR/6c7512fd2ba4eac3a10fe4203fa00b2d to your computer and use it in GitHub Desktop.
Text to old-school phone keyboard
This file contains 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
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