The Deslangifier In this assignment, you are writing a program that converts c
ID: 3774992 • Letter: T
Question
The Deslangifier In this assignment, you are writing a program that converts common texting abbreviations to English words to allow people like yours truly can understand. OMG! For the assignment, you are provided with a .txt file, called TextToEnglish.txt, that provides the abbreviations and their English translation. The file contains GRated translations only. The txt file has comma separated values that list the key as the first item, a comma to separate the key from the value, and then the value. For this assignment, you need to submit one file called Assignment10_LastName.py, where LastName is your last name. Please include comments in your code that explain what your code is doing. The comments should also include your name, recitation TA, and the assignment number. Each function should be commented with the functions purpose and description of the parameters. Steps: 1. Write a function, called CreateDictionary that is given the name of the text file to be read. The function opens the given file, reads in data, and generates a dictionary. The dictionary key is the text abbreviation and the value is the English translation. For example, one entry in your dictionary will be, ‘l8’: ‘late’ because one of the rows in the txt file contains ‘l8’ and ‘late’. Your function should have one input: the name of the file to open, and one return value: the dictionary. Test your function before moving on to the next step. You can do this by defining the function and then calling it in your .py file: wordDictionary = CreateDictionary(filename) 2. Write a function Deslang(…) that takes two parameters, a string and a dictionary, and returns the deslanged string. Each word in the string will be replaced if it has an entry in the dictionary. Any word not in the dictionary should be copied to the results. deslanged = Deslang(slang, wordDictionary) For example, if the slang string is: “David, y r u l8” your function should return: “David, why are you late” 3. Your main function in the .py file containing your functions, CreateDictionary, and Deslang, should do the following: a. Call the CreateDictionary function. b. Prompt the user for a text abbreviation and check if it is in the dictionary. If it is, print the English words associated with the abbreviation, otherwise print “Not Found”. Your main must also allow the user to continue inputting abbreviations and printing the English meaning of those abbreviations until the user enters “quit”. c. Prompt the user for an arbitrary number of text abbreviations, separated by a space, and print a string that displays the meaning of all abbreviations (by calling the Deslang function). Your main must also allow the user to continue inputting sentences with abbreviations and printing the English meaning of those sentences without abbreviations until the user enters “quit”. For this assignment, will be testing your code by importing your code into our own .py files and calling your functions. We will not use your main function. Therefore, your functions for CreateDictionary and Deslang should not produce any output or require any input from user. You can test this by creating another .py file that imports your assignment into it and has its own main function that calls your required functions.
Explanation / Answer
data = {} # dict: list of all values for person by person name with open("TextToEnglish.txt", "rt") as f: data_key = f.readline() # We remember first line (first man) data[data_key] = [] # empty list of values for line in f: # then we suppose every line is float. try: # convert to float value = float(line.strip()) # add to data data[data_key].append(value) # If it does not convert, then it is next person except ValueError: # next person's name data_key = line # new list data[data_key] = [] for employee, stats in data.iteritems(): print employee
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.