Created
January 14, 2015 15:50
-
-
Save montycheese/8629096d736c02f3b964 to your computer and use it in GitHub Desktop.
Acronym expander
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
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
http://www.reddit.com/r/dailyprogrammer/comments/2ptrmp/20141219_challenge_193_easy_acronym_expander/