Question: Write a program in python that reads in the text file attached, converts all words to lowercase, and prints out all words in the file
Write a program in python that reads in the text file attached, converts all words to lowercase, and prints out all words in the file that begin with that key letter a the letter b and so on Build a dictionary whose keys are the lowercase letters, and whose values are sets of words which begin with that key letter. After processing the data, print the dictionary to the screen in alphabetical order aligned in two fixed sized columns. Such as:
a add 'alpha', at
b both 'but', 'box'
Do not add duplicate words to the dictionary.
Your program must be thoroughly documented.
The beginning of the program should include comments that define assumptions and executionoperation instructions.
This means a block of comments before each function, and before major segments of code that define, inputs, outputs, and functionality.
This also means comprehensive individual line comments that explain the contribution of each line of the code. DO NOT define syntax in your comments, rather explain how that contributes to the functional goals of your overall program.
Attach your finished program and word file to this link in zip format.
without using import string or letterdict letter: set for letter in string.asciilowercase
Heres what i have so far:
worddict dict
try:
#opens the Wordstxt file and catches any errors
wordfile openinfile,r
except:
printcould not open file:" infile
exit
#loop through the file & converts it to lowercase
for Word in wordfile:
word Word.lowerrstrip
#reads through the text file and if it comes across a new word it will
#convert it into either a key or a value and will sort it accordingly
if word not in worddict.keys:
worddictword set
worddictwordaddword
else:
worddictwordaddword
#closes the file
wordfile.close
#return to the main function
return worddict
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
