# # by Prof. Dipak Ghosal # # # Comments and some code by Matt Bishop, MHI 29I, Winter 2018 # # The abbreviations are stored in the file "abbreviations.txt" # The format is: # abbreviation:expansion # for example, # brb:be right back # if you have 2 or more colons, only the first two fields are used # def main(): # # open the file with the abbreviations # try: infile = open("abbreviations.txt", "r") except EOFError: return except Exception as msg: print "abbreviations.txt:", msg return # # parse the contents of the file and # set up the dictionary # d = {} for line in infile: # abbreviation is first, then expansion # ignore anything else temp = line.split(":") # dump the word in the dictionary # after stripping off the newline # and any trailing white space d[temp[0]]=temp[1].rstrip() # done with the file! infile.close() # # now process the input # try: im = raw_input("Please input the IM ") except EOFError: return except Exception as msg: print msg return # start the output line, and break the input line # into words tim = "" templist = im.split() # loop through the words, suobstituting as needed first = True for i in templist: t = d.get(i, i) if first: tim = t; first = False else: tim = tim + " " + t # print the conversion print tim main()