Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python program help? Steps: Write a function, called CreateDictionary that is gi

ID: 3773914 • Letter: P

Question

Python program help?


Steps:

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)


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”.

Explanation / Answer

# -*- coding: utf-8 -*-
import csv

def CreateDictonary(filename):
"""Summary line.
  
This function take csv file name as argumnet which has contain two
column.column first has abbreviation and other has English translation.
we convert this csv to dictonary.In this dictonary key is abbreviation
and value is Translation
  
Parameters
----------
filename : str
Description of arg1
  
Returns
-------
dict
Dictonary containing abbreviation as key and translation as value

"""
word_dict={}
with open(filename, newline='') as csvfile:
spamreader = csv.reader(csvfile)
for row in spamreader:
word_dict[row[0]] = row[1]
return word_dict

def Deslang(slang, wordDictionary):
  
"""Summary line.
  
This function take two argument first is string and second is dictonary
of abbreviation and translation. we replace all occurance of abbreviation
with there translation.
  
Parameters
----------
string : str
string which contain slangs
wordDictonary:dict
  
Returns
-------
string which will not contain slangs
  

"""
out_str=slang.split(" ")
for i in range(len(out_str)) :
if out_str[i] in wordDictionary:
out_str[i] = wordDictionary[out_str[i]]
return " ".join(out_str)
  
  
if __name__ == '__main__':
wordDictonary = CreateDictonary('input.csv')
flag=""
while flag!="quit":
abvr = input()
print(Deslang(abvr,wordDictonary))
flag = abvr