Last active
August 13, 2016 01:43
-
-
Save Pela647/ab72d590379593dc1f7726eac922a60e to your computer and use it in GitHub Desktop.
Translates short codes in SMS to meaningful words.
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
#Sample code for SMS decoder | |
import re, string | |
def chatDecoder(): | |
abr=['b1','141','AA','AAK','AAF','A3','LOL','IAAG','FR'] | |
longAbr=['be one','one for all and all for one','Ask about','Alive and kicking/Asleep at keyboard','As a friend/As a matter of fact','Anytime, Anywhere, Anyplace',\ | |
'laugh out loud','i am a Genuis','for real'] | |
message=input("What message do you want decoded? \n") | |
translator = str.maketrans({key: None for key in string.punctuation}) | |
message=message.translate(translator) | |
messageToList=message.split() # change a sentence into a list so that i can loop through the words. | |
for i in messageToList: | |
modifiedMessage="" | |
for j in abr: | |
#if i==j: | |
if re.fullmatch(i, j, re.IGNORECASE): | |
i=longAbr[abr.index(j)] | |
# here italicize i | |
else: | |
i=i | |
modifiedMessage+=i | |
modifiedMessage=modifiedMessage.lower() | |
print(modifiedMessage, end=" ") # The end=" ", prints the output horizontally | |
print(".") | |
return | |
chatDecoder() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment