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 execution/operation 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 goal(s) of your overall program.
Attach your finished program and word file to this link in zip format.
without using import string or letter_dict ={letter: set() for letter in string.ascii_lowercase}
Heres what i have so far:
word_dict = dict()
try:
#opens the Words2.txt file and catches any errors
word_file = open(in_file,'r')
except:
print("could not open file:" + in_file)
exit
#loop through the file & converts it to lowercase
for Word in word_file:
word = Word.lower().rstrip()
#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 [0] not in word_dict.keys():
word_dict[word[0]]= set()
word_dict[word[0]].add(word)
else:
word_dict[word[0]].add(word)
#closes the file
word_file.close()
#return to the main function
return word_dict

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!