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

Sample of TEXT FILE This is what i have so far. I need help with part 2 def Crea

ID: 3776886 • Letter: S

Question

Sample of TEXT FILE

This is what i have so far. I need help with part 2

def CreateDictionary(filename):
   dictionary = {}
   myfile = open(filename, "r")
  
   for line in myfile.read().splitlines():
       data = line.split(",")
       key = data[0]
       value = data[1]
         
       dictionary[key] = value
      
   return dictionary
      
def DeSlang(slang, wordDictionary):
   check = 0
   output = ""
  
   for item in slang:
      
  
   for

      
  
def main():
   wordDictionary = CreateDictionary("textToEnglish.txt")
   userinput = raw_input("Please a sentence you wish to deslang: ").split(" ")
  
   DeSlang(userinput, wordDictionary)
  
if __name__ == "__main__":
   main()

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, 18' 'late' because one of the rows in the txt file contains "18' 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 word Dictionary CreateDictionary filename) 2. Write a function DeslangC. 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 ru18" your function should return: "David, why are you late"

Explanation / Answer

def CreateDictionary(filename):
dictionary = {}
myfile = open(filename, "r")
  
for line in myfile.read().splitlines():
data = line.split(",")
key = data[0]
value = data[1]
dictionary[key] = value
  
return dictionary
  
def DeSlang(slang, wordDictionary):
output = ""
for item in slang:
# if item is a key of wordDictionary then get value of that key and add to output
if item in wordDictionary.keys():
output += wordDictionary[item]
else:
output += item
output = output + " "
return output
  
def main():
wordDictionary = CreateDictionary("textToEnglish.txt")
userinput = raw_input("Please a sentence you wish to deslang: ").split(" ")
  
print DeSlang(userinput, wordDictionary)
  
if __name__ == "__main__":
main()

"""
sample output
Please a sentence you wish to deslang: 2day was 1daful
today was wonderful

"""

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote