Skip to content

Instantly share code, notes, and snippets.

@montycheese
Created January 14, 2015 15:50
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 montycheese/8629096d736c02f3b964 to your computer and use it in GitHub Desktop.
Save montycheese/8629096d736c02f3b964 to your computer and use it in GitHub Desktop.
Acronym expander
abbvr = {
"lol": "laugh out loud",
"dw": "don't worry",
"hf": "have fun",
"gg": "good game",
"brb": "be right back",
"g2g": "got to go",
"wtf": "what the fuck",
"wp": "well played",
"gl": "good luck",
"imo": "in my opinion"
}
def main():
msg = raw_input(">> ")
words = []
punctuation = []
temp = ""
count = 0
for char in msg:
if char.isalnum():
temp += char
if char == msg[len(msg)-1] and count == len(msg)-1:
words.append(temp)
elif char == "." or char == "," or char == "!" or char == ":" or char == ";":
punctuation.append(char)
if temp != "":
words.append(temp)
temp = ""
else:
punctuation.append(char)
words.append(temp)
temp = ""
count += 1
#end for
new_word = ""
count = 0
for word in words:
if word in abbvr.keys():
new_word += abbvr[word]
else:
new_word += word
try:
new_word += punctuation[count]
except IndexError:
continue
count +=1
print new_word
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment