Write a program that prompts the user for a filename. Open the file, and read it one line at a time. For each line split the line into a list of words called line_list. For each word in the current line_list, convert the word to lowercase and look to see if it is in a list called script_list (a list that is initially empty). If the word is not in script_list, add it to the script_list. Sort the script_list alphabetically.

Within the same program define a function called freq_count(). This function accepts a str and a list of words as arguments. It traverses the list of words and searches each word and counts the occurrences of the substring str within each word. Print each word along with the number of substring occurrences found within the associated word. Please note that you are not counting the number of occurrences in the file!

Modify your program so that it accepts the filename and the substring str as input from the user. After reading the file to build and sort the script_list, pass the script_list into the freq_count() function. Test your program with the romeo.txt file that comes as a text file resource with our textbook.

Note: With step 2, you are printing each word, not just words with non-zero occurrences of the substring str. As examples of what the substring search results would be, given the word "there" and a substring str of th, the result would be 1, and the print result for that one word would be there 1; given the same word there and a substring str of e, the result would be 2, and the print result for that one word would be there 2; and finally, given the same word there and a substring str of z, the result would be 0, and the print result for that one word would be there 0.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.