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

I\'m creating this program in Python that reads a .txt file, converts the conten

ID: 3602052 • Letter: I

Question

I'm creating this program in Python that reads a .txt file, converts the contents to lower case, and prints an alphabetized table of all the different words in the file while showing how many times each word appears in the file.

But I'm having trouble alphabetizing the words. How do I do this?

f - open( "/Users/admin/Desktop/doves.txt""r) countWord = {} for word in f.read().split(): lowerCaseWord = word.lower() if lowerCaseWord not in countWord: countWord [lowerCaseWoraj - 1 else: countWord[lowerCaseWord] - countWord[ lowerCaseWord] + 1 for key,value in countWord.items (): print (key, value) ('kiss', 1) ('just', ("don't", 6) ('satisfied', 3) ( 'touch', ('father', 3) ("pride', 1) ('mother)', 1) ("you've", 1) ('they', 1) ('world', 4) ('pose

Explanation / Answer

Python has a built-in function named sorted(iterable), which takes any iterable object and sort it in ascending order by default and returns a list. In case of a dictionary, sorted(dictionary) will return a list of the keys in sorted order.

Code:

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