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()
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
"""
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.