Skip to content

Instantly share code, notes, and snippets.

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 TApicella/da5f53a1d35b76732fe8a61ba886d712 to your computer and use it in GitHub Desktop.
Save TApicella/da5f53a1d35b76732fe8a61ba886d712 to your computer and use it in GitHub Desktop.
DailyProgrammer 5-16-2017 Txt acronyms created by tapicella - https://repl.it/IBGV/10
'''
On console input you will be given a string that represents the abbreviated chat message.
Output. Output should consist of the expanded sentence.Wordlist
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
input
wtf that was unfair
output
what the fuck that was unfair
gl all hf
'good luck all have fun'
imo that was wp. anyway i've g2g
'in my opinion that was well played. anyway i've got to go.
'''
acroLookup = {
"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"
}
phraseLookup = {
'laugh out loud':"lol",
"don't worry": "dw",
'have fun': "hf",
'good game': "gg",
'be right back': "brb",
'got to go': "g2g",
'what the fuck': "wtf",
'well played': "wp",
'good luck': "gl",
'in my opinion': "imo"
}
def toPhrase(myString):
splitstring = myString.split(' ')
for w in range(len(splitstring)):
if splitstring[w] in acroLookup:
splitstring[w] = acroLookup[splitstring[w]]
return ' '.join(splitstring)
def condense(myString):
stack = []
result = ""
splitstring = myString.split(' ')
for w in range(len(splitstring)):
stack.append(splitstring[w])
for i in range(len(stack)):
testword = ' '.join(stack[i:])
if testword in phraseLookup:
if i!=0:
result += ' '.join(stack[0:i])+' '
result += phraseLookup[testword]+' '
stack = []
result += ' '.join(stack)
result = result.strip()
return result
return ' '.join(splitstring)
def userInput():
new_input = input("Input your . Submit a blank input to finish typing\n")
final_input = new_input
while new_input.strip() !='':
final_input+='\n'
new_input = input()
final_input+=new_input
return final_input
myinput = input("Type in the phrase you want converted:\n")
whichone = input("Do you want to expand phrases or condense them?\n")
if whichone=="expand": #Terrible input handling, but fine for this example
print(toPhrase(myinput))
else:
print(condense(myinput))
print(toPhrase("wtf lol noob"))
print(condense("what the fuck laugh out loud noob"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment