Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using PyCharm (Python), modify the Gettysburg processing program to generate a text file from an output rather than printing to the screen. Your program should

Using PyCharm (Python), modify the Gettysburg processing program to generate a text file from an output rather than printing to the screen. Your program should have a new function called process_file which prints to the file (this method should almost be the same as the pretty_print function from last week. Keep in mind that we have print statements in main as well. Your program must modify the print statements from main as well. Your program must have a header. Create a new function called process_fie. This function will perform the same operations as pretty_print from week 8 however it will print to a file instead of to the screen. Modify your main method to print the length of the dictionary to the file as opposed to the screen. This will require that you open the file twice. Once in main and once in process_file. Prompt the user for the filename they wish to use to generate the report. Use the filename specified by the user to write the file. This will require you to pass the file as an additional parameter to your new process_file function. The output should be from high to low frequency (text) and use string formatting for this.

I do not understand how to put it in frequency order from high to low and not sure on the printing the file.

main_dict = {} def add_word( dataVal ): count = 1 if dataVal in main_dict: main_dict[dataVal] = main_dict[dataVal] + count else: main_dict.update({dataVal: count}) def Process_line( data ): data_list = data.split(" ") for val in data_list: add_word(val.replace(" ", "").replace(",", "").replace(".", "").replace("-", "")) def Pretty_print(): print("length of the dictionary:", len(main_dict)) print("word\tcount ") print("-------------") for key, val in main_dict.items(): print("{}\t{}".format(key, str(val))) if __name__ == "__main__": f = open("gettysburg.txt", "r") for line in f.readlines(): Process_line(line) print(Pretty_print())

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions